fix: Handle errors when getting changed files in reviewer (#413)

This commit is contained in:
Brace Sproul 2025-07-15 11:21:16 -07:00 • committed by GitHub
parent 0baea2350e
commit 58ab44f515
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,6 +9,8 @@ import { GraphConfig } from "@open-swe/shared/open-swe/types";
import { AIMessage, ToolMessage } from "@langchain/core/messages";
import { v4 as uuidv4 } from "uuid";
import { createReviewStartedToolFields } from "@open-swe/shared/open-swe/tools";
import { getSandboxErrorFields } from "../../../utils/sandbox-error-fields.js";
import { Sandbox } from "@daytonaio/sdk";
const logger = createLogger(LogLevel.INFO, "InitializeStateNode");
@ -43,6 +45,32 @@ function createReviewStartedMessage() {
];
}
async function getChangedFiles(
sandbox: Sandbox,
baseBranchName: string,
repoRoot: string,
): Promise<string> {
try {
const changedFilesRes = await sandbox.process.executeCommand(
`git diff ${baseBranchName} --name-only`,
repoRoot,
);
if (changedFilesRes.exitCode !== 0) {
const errorFields = getSandboxErrorFields(changedFilesRes);
logger.error(
`Failed to get changed files: ${JSON.stringify(errorFields, null, 2)}`,
);
}
return changedFilesRes.result.trim();
} catch (e) {
const errorFields = getSandboxErrorFields(e);
logger.error("Failed to get changed files.", {
...(errorFields ? { errorFields } : { e }),
});
return "Failed to get changed files.";
}
}
export async function initializeState(
state: ReviewerGraphState,
config: GraphConfig,
@ -72,16 +100,7 @@ export async function initializeState(
baseBranchName = baseBranchNameRes.result.trim();
}
const changedFilesRes = await sandbox.process.executeCommand(
`git diff ${baseBranchName} --name-only`,
repoRoot,
);
if (changedFilesRes.exitCode !== 0) {
throw new Error(
`Failed to get changed files: ${JSON.stringify(changedFilesRes, null, 2)}`,
);
}
const changedFiles = changedFilesRes.result.trim();
const changedFiles = await getChangedFiles(sandbox, baseBranchName, repoRoot);
logger.info("Finished getting state for reviewer");