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-beep3ce5f9befa79
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 b229b30ec4..e5ffc96f66 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -2081,6 +2081,37 @@ describe("pane refit", () => {
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 025ad61d07..ea28ad3849 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -70,6 +70,7 @@ import {
} from "lucide-react";
import { SplitBelowIcon, SplitRightIcon } from "./splitIcons";
import {
+ holdsSizeLead,
mayLeadSize,
onSizeLeadReleased,
releaseSizeLead,
@@ -697,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;
@@ -1593,8 +1603,9 @@ export function AgenticTerminal({
* every GESTURE_RECLAIM_MS. See ./paneSizeLead.
*/
const leadKey = sizeLeadKey(workspaceId, name);
- const leadToken = {};
- if (sizeLead) takeSizeLead(leadKey, leadToken);
+ const leadToken = leadTokenRef.current;
+ if (sizeLead || heldLeadRef.current) takeSizeLead(leadKey, leadToken);
+ heldLeadRef.current = false;
const mayLead = () => mayLeadSize(leadKey, leadToken);
/*
@@ -1881,7 +1892,10 @@ export function AgenticTerminal({
*/
const stopLeadWatch = onSizeLeadReleased(leadKey, () => {
if (disposed) return;
- claimResize();
+ // 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);
});
/*
@@ -2264,6 +2278,9 @@ export function AgenticTerminal({
// 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();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts
index 3db5b1f4ee..884176909f 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from "vitest";
-import { mayLeadSize, onSizeLeadReleased, releaseSizeLead, sizeLeadKey, takeSizeLead } from "./paneSizeLead";
+import { holdsSizeLead, mayLeadSize, onSizeLeadReleased, releaseSizeLead, sizeLeadKey, takeSizeLead } from "./paneSizeLead";
const flush = () => Promise.resolve();
@@ -13,7 +13,9 @@ describe("pane size lead", () => {
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.
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts
index 8676fdf332..008ff96c8e 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSizeLead.ts
@@ -57,6 +57,11 @@ export function releaseSizeLead(key: string, token: SizeLeadToken): void {
});
}
+/** 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);