Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: don't poll git info when no workspace is attached to conversation (#919)

Ash Clarke0b98b618c110
diff --git a/__tests__/hooks/query/use-local-git-info.test.tsx b/__tests__/hooks/query/use-local-git-info.test.tsx
index fa8f324635..e6967654da 100644
--- a/__tests__/hooks/query/use-local-git-info.test.tsx
+++ b/__tests__/hooks/query/use-local-git-info.test.tsx
@@ -67,6 +67,16 @@ const conversationWithoutRepo = {
selected_branch: null,
};
+const conversationWithoutWorkspace = {
+ id: "conv-2",
+ conversation_url: "https://runtime.example.com/api/conversations/conv-2",
+ session_api_key: "session-key",
+ workspace: null,
+ selected_repository: null,
+ git_provider: null,
+ selected_branch: null,
+};
+
describe("useLocalGitInfo", () => {
beforeEach(() => {
useActiveBackendMock.mockReset();
@@ -114,6 +124,31 @@ describe("useLocalGitInfo", () => {
);
});
+ it("does not poll when the conversation has no workspace attached, even on a local backend", async () => {
+ // Arrange
+ useActiveBackendMock.mockReturnValue(makeBackend("local"));
+ useActiveConversationMock.mockReturnValue({
+ data: conversationWithoutWorkspace,
+ });
+
+ // Act
+ const { result } = renderHook(() => useLocalGitInfo(), {
+ wrapper: makeWrapper(),
+ });
+
+ // Assert: query stays disabled; no bash commands are issued.
+ await new Promise((resolve) => {
+ setTimeout(resolve, 20);
+ });
+ expect(result.current.fetchStatus).toBe("idle");
+ expect(runCommandMock).not.toHaveBeenCalled();
+ expect(useBashCommandRunnerMock).toHaveBeenCalledWith(
+ conversationWithoutWorkspace.conversation_url,
+ conversationWithoutWorkspace.session_api_key,
+ false,
+ );
+ });
+
it("probes git metadata via the bash runner on a local backend when conversation metadata is incomplete", async () => {
// Arrange
useActiveBackendMock.mockReturnValue(makeBackend("local"));
diff --git a/src/hooks/query/use-local-git-info.ts b/src/hooks/query/use-local-git-info.ts
index 74390dc351..c7c5347ee9 100644
--- a/src/hooks/query/use-local-git-info.ts
+++ b/src/hooks/query/use-local-git-info.ts
@@ -2,7 +2,6 @@ import { useQuery } from "@tanstack/react-query";
import { useRef } from "react";
import type { CommandResult } from "#/api/runtime-service/agent-server-runtime-service";
-import { getAgentServerWorkingDir } from "#/api/agent-server-config";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useActiveConversation } from "#/hooks/query/use-active-conversation";
import { useRuntimeIsReady } from "#/hooks/use-runtime-is-ready";
@@ -103,8 +102,7 @@ export const useLocalGitInfo = () => {
const conversationId = conversation?.id;
const conversationUrl = conversation?.conversation_url;
const sessionApiKey = conversation?.session_api_key;
- const workingDir =
- conversation?.workspace?.working_dir?.trim() || getAgentServerWorkingDir();
+ const workingDir = conversation?.workspace?.working_dir?.trim();
const hasConversationRepo = !!conversation?.selected_repository;
const hasConversationProvider = !!conversation?.git_provider;
const hasConversationBranch = !!conversation?.selected_branch;
@@ -113,6 +111,7 @@ export const useLocalGitInfo = () => {
isLocalBackend &&
runtimeIsReady &&
!!conversationId &&
+ !!workingDir &&
(!hasConversationRepo ||
!hasConversationProvider ||
!hasConversationBranch);
@@ -146,7 +145,8 @@ export const useLocalGitInfo = () => {
queryFn: async () => {
const run: RunCommand = (command, cwd, timeout) =>
runCommandRef.current(command, cwd, timeout);
- return probeGitInfo(run, workingDir);
+ // workingDir is guaranteed non-empty by the queryEnabled guard above.
+ return probeGitInfo(run, workingDir!);
},
enabled: queryEnabled,
retry: false,