Fix terminal state infinite loop, test ordering assertion, and redundant updateBranch call

- ChatView: Stabilize terminalIds/terminalGroups dependencies by using
  JSON.stringify so React compares by value instead of reference, preventing
  an infinite write loop when normalizeThreadTerminals creates new arrays.
- persistenceService.test: Fix catchUp ordering assertion to compare each
  event's seq against the previous event's seq instead of itself.
- BranchToolbar: Remove redundant api.threads.updateBranch call since the
  useEffect in ChatView already syncs branch changes to the server.
This commit is contained in:
Cursor Agent committed 2026-02-20 00:29:10 +00:00
1 parent 384878a3f1
commit ab955ddbb9
3 files changed
+11 -6

No files matched your search

+5 -3
View File
@@ -125,9 +125,11 @@ describe("PersistenceService", () => {
const catchUp = service.catchUp({ afterSeq: 0 });
expect(catchUp.events.length).toBeGreaterThan(0);
expect(catchUp.events.every((event, index, events) => event.seq === events[index]?.seq)).toBe(
true,
);
expect(
catchUp.events.every(
(event, index, events) => index === 0 || event.seq > events[index - 1]!.seq,
),
).toBe(true);
expect(catchUp.events.some((event) => event.eventType === "project.upsert")).toBe(true);
expect(catchUp.events.some((event) => event.eventType === "thread.upsert")).toBe(true);
expect(catchUp.events.some((event) => event.eventType === "message.upsert")).toBe(true);
@@ -120,7 +120,6 @@ export default function BranchToolbar({
if (sessionId && worktreePath !== activeWorktreePath) {
void api?.providers.stopSession({ sessionId }).catch(() => undefined);
}
void api?.threads.updateBranch({ threadId: activeThreadId, branch, worktreePath }).catch(() => undefined);
dispatch({ type: "SET_THREAD_BRANCH", threadId: activeThreadId, branch, worktreePath });
};
+6 -2
View File
@@ -782,6 +782,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
.catch(() => undefined);
}, [activeThread?.id, activeThread?.branch, activeThread?.worktreePath, api]);
const terminalIdsKey = JSON.stringify(activeThread?.terminalIds ?? null);
const terminalGroupsKey = JSON.stringify(activeThread?.terminalGroups ?? null);
useEffect(() => {
if (!api || !activeThread) return;
void api.threads
@@ -795,13 +798,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
activeTerminalGroupId: activeThread.activeTerminalGroupId,
})
.catch(() => undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
activeThread?.id,
activeThread?.terminalOpen,
activeThread?.terminalHeight,
activeThread?.terminalIds,
terminalIdsKey,
activeThread?.activeTerminalId,
activeThread?.terminalGroups,
terminalGroupsKey,
activeThread?.activeTerminalGroupId,
api,
]);