Skip to content

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.

fix(agentic-ide): stop two viewers of one pane in one window trading its size

rubenluetke10-beep586d22f63d86
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
index d84ad6854e..e5ffc96f66 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -16,6 +16,12 @@ const terminalHarness = vi.hoisted(() => ({
handlers: { current: null as Record<string, (...args: never[]) => void> | null },
/** What the pane opened its socket WITH — the handshake size among it. */
opened: { current: null as Record<string, unknown> | null },
+ /** Every socket opened, oldest first, with the frames sent on it — for two viewers of one pane. */
+ sockets: [] as {
+ options: Record<string, unknown>;
+ handlers: Record<string, (...args: never[]) => void>;
+ sent: unknown[];
+ }[],
/** Everything the pane types into the terminal on the user's behalf. */
input: vi.fn<(data: string) => void>(),
/** xterm's single custom key handler, so a test can press a key. */
@@ -172,8 +178,13 @@ vi.mock("./paneSocket", () => ({
) => {
terminalHarness.opened.current = options as Record<string, unknown>;
terminalHarness.handlers.current = handlers;
+ const record = { options: options as Record<string, unknown>, handlers, sent: [] as unknown[] };
+ terminalHarness.sockets.push(record);
return {
- send: (payload: unknown) => terminalHarness.send(payload),
+ send: (payload: unknown) => {
+ record.sent.push(payload);
+ return terminalHarness.send(payload);
+ },
close() {},
};
},
@@ -1976,6 +1987,132 @@ describe("pane refit", () => {
rows: 24,
});
});
+
+ /*
+ * One pane, two viewers in ONE window: the office's pane window over the
+ * same pane in the IDE grid. The cross-window rule (a gesture anywhere takes
+ * a displaced pane back) had both of them take the size from each other on
+ * every mouse move, two seconds apart — the agent redrawing for a wide and a
+ * narrow screen in turn, the office window flickering with its text squeezed
+ * into the left third (2026-09-29). The viewer opened as the pane's lead
+ * keeps the size; the other follows it, and takes the size back only when
+ * the lead is gone.
+ */
+ describe("two viewers of one pane in one window", () => {
+ const claimsOn = (index: number) =>
+ terminalHarness.sockets[index].sent.filter(
+ (frame) => (frame as { t: string }).t === "claim",
+ );
+ const open = (index: number) =>
+ act(() => {
+ terminalHarness.sockets[index].handlers.onOpen?.();
+ });
+ const displace = (index: number) =>
+ act(() => {
+ terminalHarness.sockets[index].handlers.onGeometry?.({ cols: 30, rows: 10 } as never);
+ });
+ const clearSent = () => {
+ for (const socket of terminalHarness.sockets) socket.sent.length = 0;
+ };
+ const grid = <AgenticTerminal key="grid" name="Dana" displayName="Claude Code" appearance="dark" fontSize={13} />;
+ const office = <AgenticTerminal key="office" name="Dana" displayName="Claude Code" appearance="dark" fontSize={13} sizeLead headerMode="none" />;
+
+ beforeEach(() => {
+ terminalHarness.sockets = [];
+ });
+
+ it("leaves the size with the lead instead of taking it back on a gesture", () => {
+ render(<>{grid}{office}</>);
+ open(0);
+ open(1);
+ settle();
+ // The office window claimed the pane; the grid behind it now shows its geometry.
+ displace(0);
+ clearSent();
+
+ fireEvent.pointerMove(document.body);
+ settle();
+ fireEvent.keyDown(document.body, { key: "a" });
+ settle();
+
+ expect(claimsOn(0)).toEqual([]);
+ });
+
+ it("hands the size back to the grid when the lead closes", async () => {
+ const view = render(<>{grid}{office}</>);
+ open(0);
+ open(1);
+ settle();
+ displace(0);
+ clearSent();
+
+ view.rerender(<>{grid}</>);
+ // The hand-over waits a microtask, so a lead that merely rebuilds keeps the size.
+ await act(async () => {
+ await Promise.resolve();
+ });
+ settle();
+
+ expect(claimsOn(0)).toEqual([{ t: "claim", cols: 80, rows: 24 }]);
+ });
+
+ it("gives the lead to the viewer the user presses", () => {
+ const view = render(<>{grid}{office}</>);
+ open(0);
+ open(1);
+ settle();
+ displace(0);
+ clearSent();
+
+ // A press on the grid's pane is an explicit choice: it takes the size…
+ const hosts = view.getAllByTestId("agentic-terminal-host-Dana");
+ fireEvent.mouseDown(hosts[0]);
+ settle();
+ expect(claimsOn(0)).toEqual([{ t: "claim", cols: 80, rows: 24 }]);
+
+ // …and the office window, now the one displaced, no longer takes it back
+ // on the next mouse move.
+ displace(1);
+ clearSent();
+ act(() => {
+ vi.advanceTimersByTime(2_500);
+ });
+ fireEvent.pointerMove(document.body);
+ settle();
+ expect(claimsOn(1)).toEqual([]);
+ });
+
+ it("keeps the lead through a rebuild of the viewer that holds it", async () => {
+ // A restart (or the font arriving) rebuilds the terminal inside the same
+ // viewer. Coming back leaderless let the other viewer pass the gesture
+ // test again, and the two traded the size as before the fix.
+ const pressed = (token: number) => (
+ <AgenticTerminal key="grid" name="Dana" displayName="Claude Code" appearance="dark" fontSize={13} restartToken={token} />
+ );
+ const view = render(<>{pressed(0)}{office}</>);
+ open(0);
+ open(1);
+ settle();
+ fireEvent.mouseDown(view.getAllByTestId("agentic-terminal-host-Dana")[0]);
+ settle();
+
+ view.rerender(<>{pressed(1)}{office}</>);
+ await act(async () => {
+ await Promise.resolve();
+ });
+ open(2);
+ settle();
+ displace(1);
+ clearSent();
+ act(() => {
+ vi.advanceTimersByTime(2_500);
+ });
+ fireEvent.pointerMove(document.body);
+ settle();
+
+ expect(claimsOn(1)).toEqual([]);
+ });
+ });
});
/*
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 065304937e..ea28ad3849 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -69,6 +69,14 @@ import {
X,
} from "lucide-react";
import { SplitBelowIcon, SplitRightIcon } from "./splitIcons";
+import {
+ holdsSizeLead,
+ mayLeadSize,
+ onSizeLeadReleased,
+ releaseSizeLead,
+ sizeLeadKey,
+ takeSizeLead,
+} from "./paneSizeLead";
// A leaf module with no DOM and no terminal in it, which is the point: the
// wizard quotes this same number before any pane exists — see ./layout.
import { cn } from "@/lib/utils";
@@ -628,6 +636,13 @@ interface AgenticTerminalProps {
* one, and the backend spawns a new agent for it.
*/
restartToken?: number;
+ /**
+ * Open as THE view of this pane in this window: while mounted it sizes the
+ * pane, and the same pane's other viewers here (the IDE grid behind the
+ * office's pane window) follow it instead of taking the size back on every
+ * gesture. Read at mount. See ./paneSizeLead.
+ */
+ sizeLead?: boolean;
}
export function AgenticTerminal({
@@ -670,6 +685,7 @@ export function AgenticTerminal({
showArrangeHandle = false,
arranging = false,
layoutBusy = false,
+ sizeLead = false,
}: AgenticTerminalProps) {
const containerRef = useRef<HTMLDivElement | null>(null);
const terminalRegionRef = useRef<HTMLDivElement | null>(null);
@@ -682,6 +698,15 @@ export function AgenticTerminal({
const claimResizeRef = useRef<(() => void) | null>(null);
/** The claim a gesture inside the pane makes — see `takeOwnership`. */
const takeOwnershipRef = useRef<(() => void) | null>(null);
+ /**
+ * This viewer's identity in the window's size-lead registry (./paneSizeLead),
+ * and whether it held the lead when its terminal was last torn down. Both
+ * outlive the connect effect: a rebuild (a restart, the font arriving, the
+ * grid settling) is the same viewer, and must come back holding the lead it
+ * had rather than leaving the pane leaderless for another viewer to claim.
+ */
+ const leadTokenRef = useRef<object>({});
+ const heldLeadRef = useRef(false);
const visibilityRef = useRef<{
show: (afterFlush?: () => void) => void;
park: () => void;
@@ -1570,6 +1595,18 @@ export function AgenticTerminal({
let owned = false;
/** Is this pane showing a geometry another viewer chose? See reclaimOnGesture. */
let displaced = false;
+ /*
+ * This viewer's place among the pane's viewers in THIS window. The server
+ * settles who sizes the pane between windows; inside one, a second viewer
+ * of the same pane (the office's pane window over the IDE grid) would
+ * otherwise take the size back on every gesture and the two would trade it
+ * every GESTURE_RECLAIM_MS. See ./paneSizeLead.
+ */
+ const leadKey = sizeLeadKey(workspaceId, name);
+ const leadToken = leadTokenRef.current;
+ if (sizeLead || heldLeadRef.current) takeSizeLead(leadKey, leadToken);
+ heldLeadRef.current = false;
+ const mayLead = () => mayLeadSize(leadKey, leadToken);
/*
* May this pane take the shared size without being asked to?
@@ -1589,6 +1626,7 @@ export function AgenticTerminal({
* that had just been made to fill the window (2026-08-25).
*/
const viewerMayOwn = () =>
+ mayLead() &&
activeRef.current &&
(typeof document === "undefined" ||
typeof document.hasFocus !== "function" ||
@@ -1806,9 +1844,15 @@ export function AgenticTerminal({
* desktop shell's answer to that question can lag the truth, and a click
* that is not allowed to take the pane back leaves the user with no way
* to do so at all.
+ *
+ * It also makes this viewer the pane's lead in this window, so the view
+ * the user just pressed keeps the size instead of another viewer of the
+ * same pane here taking it straight back on the next mouse move.
*/
const takeOwnership = () => {
- if (activeRef.current) sendResize(true);
+ if (!activeRef.current) return;
+ takeSizeLead(leadKey, leadToken);
+ sendResize(true);
};
takeOwnershipRef.current = takeOwnership;
/**
@@ -1828,7 +1872,10 @@ export function AgenticTerminal({
*/
let lastGestureReclaimAt = 0;
const reclaimOnGesture = () => {
- if (!displaced || !activeRef.current) return;
+ // Another viewer of this pane in this very window holds it: the gesture
+ // is as much that viewer's as this one's, and taking the size back here
+ // is what made the two trade it forever.
+ if (!displaced || !activeRef.current || !mayLead()) return;
const now = Date.now();
if (now - lastGestureReclaimAt < GESTURE_RECLAIM_MS) return;
lastGestureReclaimAt = now;
@@ -1837,6 +1884,19 @@ export function AgenticTerminal({
window.addEventListener("pointermove", reclaimOnGesture, { passive: true });
window.addEventListener("pointerdown", reclaimOnGesture, true);
window.addEventListener("keydown", reclaimOnGesture, true);
+ /*
+ * The lead viewer went away (the office's pane window closed): the size is
+ * this window's to set again, and this pane's tile is what it shows. Its
+ * own refits stayed quiet while it only watched, so nothing else would
+ * hand the agent this tile's size back.
+ */
+ const stopLeadWatch = onSizeLeadReleased(leadKey, () => {
+ if (disposed) return;
+ // A claim, not a request: the lead that just left was THIS window's,
+ // closed from here, and a request would be answered with the size the
+ // departed viewer chose — whatever the desktop shell says about focus.
+ sendResize(activeRef.current);
+ });
/*
* The size this socket connects with. The tile's own measurement when there
@@ -2215,6 +2275,13 @@ export function AgenticTerminal({
} catch {
/* ignore */
}
+ // After the socket, so this viewer is gone before another one of the
+ // pane here takes the size back.
+ stopLeadWatch();
+ // Remembered for a rebuild of this same viewer; forgotten on unmount,
+ // when nothing reads it again.
+ heldLeadRef.current = holdsSizeLead(leadKey, leadToken);
+ releaseSizeLead(leadKey, leadToken);
// Before the terminal: frees this pane's WebGL context slot.
renderer.dispose();
term.dispose();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts
new file mode 100644
index 0000000000..884176909f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts
@@ -0,0 +1,88 @@
+import { describe, expect, it, vi } from "vitest";
+import { holdsSizeLead, mayLeadSize, onSizeLeadReleased, releaseSizeLead, sizeLeadKey, takeSizeLead } from "./paneSizeLead";
+
+const flush = () => Promise.resolve();
+
+describe("pane size lead", () => {
+ it("lets every viewer size a pane nobody leads", () => {
+ const key = sizeLeadKey("ws-free", "Dana");
+ expect(mayLeadSize(key, {})).toBe(true);
+ expect(mayLeadSize(key, {})).toBe(true);
+ });
+
+ it("keeps the size with the lead and away from the pane's other viewers", () => {
+ const key = sizeLeadKey("ws-led", "Dana");
+ const office = {}, grid = {};
+ expect(holdsSizeLead(key, office)).toBe(false);
+ takeSizeLead(key, office);
+ expect(holdsSizeLead(key, office)).toBe(true);
+ expect(mayLeadSize(key, office)).toBe(true);
+ expect(mayLeadSize(key, grid)).toBe(false);
+ // Another pane, or the same name in another workspace, is not affected.
+ expect(mayLeadSize(sizeLeadKey("ws-led", "Eli"), grid)).toBe(true);
+ expect(mayLeadSize(sizeLeadKey("ws-other", "Dana"), grid)).toBe(true);
+ releaseSizeLead(key, office);
+ });
+
+ it("tells the other viewers once the lead is released", async () => {
+ const key = sizeLeadKey("ws-release", "Dana");
+ const office = {}, grid = {};
+ const heard = vi.fn(() => mayLeadSize(key, grid));
+ const stop = onSizeLeadReleased(key, heard);
+ takeSizeLead(key, office);
+
+ releaseSizeLead(key, office);
+ expect(heard).not.toHaveBeenCalled();
+ await flush();
+
+ expect(heard).toHaveBeenCalledOnce();
+ expect(heard).toHaveReturnedWith(true);
+ stop();
+ });
+
+ it("says nothing when the lead is taken again before anyone heard (a rebuild)", async () => {
+ const key = sizeLeadKey("ws-rebuild", "Dana");
+ const heard = vi.fn();
+ const stop = onSizeLeadReleased(key, heard);
+ const before = {}, after = {};
+ takeSizeLead(key, before);
+
+ releaseSizeLead(key, before);
+ takeSizeLead(key, after);
+ await flush();
+
+ expect(heard).not.toHaveBeenCalled();
+ stop();
+ releaseSizeLead(key, after);
+ });
+
+ it("releases nothing for a viewer that already lost the lead", async () => {
+ const key = sizeLeadKey("ws-lost", "Dana");
+ const heard = vi.fn();
+ const stop = onSizeLeadReleased(key, heard);
+ const office = {}, grid = {};
+ takeSizeLead(key, office);
+ takeSizeLead(key, grid);
+
+ releaseSizeLead(key, office);
+ await flush();
+
+ expect(heard).not.toHaveBeenCalled();
+ expect(mayLeadSize(key, office)).toBe(false);
+ stop();
+ releaseSizeLead(key, grid);
+ });
+
+ it("stops telling a viewer that unsubscribed", async () => {
+ const key = sizeLeadKey("ws-stop", "Dana");
+ const heard = vi.fn();
+ const office = {};
+ onSizeLeadReleased(key, heard)();
+ takeSizeLead(key, office);
+
+ releaseSizeLead(key, office);
+ await flush();
+
+ expect(heard).not.toHaveBeenCalled();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts
new file mode 100644
index 0000000000..008ff96c8e
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts
@@ -0,0 +1,85 @@
+/**
+ * Which of THIS window's viewers of a pane decides the pane's size.
+ *
+ * A pseudo-terminal has one size, and the server hands it to one viewer at a
+ * time (see `claim` in ./paneSocket). Across windows, the window the user is
+ * in wins, and a gesture anywhere in a window takes back every pane another
+ * window sized (`reclaimOnGesture` in ./AgenticTerminal). Inside ONE window
+ * that rule has no answer: two viewers of the same pane — the office's pane
+ * window and the same pane in the IDE grid behind it — both see the gesture,
+ * both are "in front", and each took the size back from the other every two
+ * seconds. The agent redrew its whole screen for each hand-over, alternating
+ * between a wide and a narrow layout: the office window flickered and showed
+ * its text squeezed into the left third (2026-09-29).
+ *
+ * So within a window a pane has at most one LEAD viewer: the one opened as the
+ * pane's focus (the office's window, while it is open) or the one the user
+ * last pressed. Every other viewer of that pane follows the lead's geometry
+ * and never claims on its own. When the lead goes away, the rest are told so
+ * they can take the size back for the tile they show.
+ *
+ * Module state on purpose: it is per window by construction, which is exactly
+ * the scope of the problem — separate windows keep the server's rule.
+ */
+
+/** A viewer's identity in the registry; any unique object will do. */
+export type SizeLeadToken = object;
+
+const leads = new Map<string, SizeLeadToken>();
+const released = new Map<string, Set<() => void>>();
+
+/** The registry key for one pane: the same name can live in two workspaces. */
+export function sizeLeadKey(workspaceId: string | undefined, name: string): string {
+ return `${workspaceId ?? ""}\u0000${name}`;
+}
+
+/** Make `token` the viewer that sizes the pane in this window. */
+export function takeSizeLead(key: string, token: SizeLeadToken): void {
+ leads.set(key, token);
+}
+
+/**
+ * Give the lead up, if `token` still holds it, and tell the pane's other
+ * viewers so one of them can size the pane again. A viewer that already lost
+ * the lead to a later press releases nothing.
+ *
+ * The others hear it a microtask later, and only if nobody took the lead in
+ * between: a lead viewer that merely rebuilds its terminal (its connect effect
+ * re-running in the same commit) must not hand the size to the grid and take
+ * it straight back — two full repaints of the agent for nothing.
+ */
+export function releaseSizeLead(key: string, token: SizeLeadToken): void {
+ if (leads.get(key) !== token) return;
+ leads.delete(key);
+ queueMicrotask(() => {
+ if (leads.has(key)) return;
+ for (const listener of [...(released.get(key) ?? [])]) listener();
+ });
+}
+
+/** Does `token` hold the pane's lead right now (not merely "nobody leads")? */
+export function holdsSizeLead(key: string, token: SizeLeadToken): boolean {
+ return leads.get(key) === token;
+}
+
+/** May `token` size the pane: it leads, or nobody in this window does. */
+export function mayLeadSize(key: string, token: SizeLeadToken): boolean {
+ const lead = leads.get(key);
+ return lead === undefined || lead === token;
+}
+
+/** Call `listener` whenever the pane's lead is released. Returns the unsubscribe. */
+export function onSizeLeadReleased(key: string, listener: () => void): () => void {
+ let set = released.get(key);
+ if (!set) {
+ set = new Set();
+ released.set(key, set);
+ }
+ set.add(listener);
+ return () => {
+ const current = released.get(key);
+ if (!current) return;
+ current.delete(listener);
+ if (current.size === 0) released.delete(key);
+ };
+}