Skip to content

Commit 1ec1021

Browse files
committed
update: swe
1 parent 313c50d commit 1ec1021

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

apps/open-swe/evals/langgraph.eval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ls.describe(DATASET_NAME, () => {
7979

8080
const encryptionKey = process.env.SECRETS_ENCRYPTION_KEY;
8181
const githubPat = process.env.GITHUB_PAT;
82-
82+
8383
if (!encryptionKey || !githubPat) {
8484
throw new Error(
8585
"SECRETS_ENCRYPTION_KEY and GITHUB_PAT environment variables are required",

apps/open-swe/langbench/evaluator.eval.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { PRData, PRProcessResult, OpenSWEStreamResults } from "./types.js";
1212
import { createPRFixPrompt } from "./prompts.js";
1313
import { runPytestOnFiles } from "./utils.js";
1414
import { v4 as uuidv4 } from "uuid";
15-
import { MANAGER_GRAPH_ID, GITHUB_PAT, GITHUB_INSTALLATION_ID } from "@open-swe/shared/constants";
15+
import { MANAGER_GRAPH_ID, GITHUB_PAT } from "@open-swe/shared/constants";
1616
import { createLangGraphClient } from "../src/utils/langgraph-client.js";
1717
import { encryptSecret } from "@open-swe/shared/crypto";
1818
import { ManagerGraphState } from "@open-swe/shared/open-swe/manager/types";
@@ -93,21 +93,19 @@ async function runOpenSWEWithStreamTracking(inputs: {
9393
try {
9494
const encryptionKey = process.env.SECRETS_ENCRYPTION_KEY;
9595
const githubPat = process.env.GITHUB_PAT;
96-
const githubInstallationId = process.env.GITHUB_INSTALLATION_ID;
9796

98-
if (!encryptionKey || !githubPat || !githubInstallationId) {
97+
if (!encryptionKey || !githubPat) {
9998
throw new Error(
100-
"SECRETS_ENCRYPTION_KEY, GITHUB_PAT, and GITHUB_INSTALLATION_ID environment variables are required"
99+
"SECRETS_ENCRYPTION_KEY and GITHUB_PAT environment variables are required",
101100
);
102101
}
103102

104103
const encryptedGitHubToken = encryptSecret(githubPat, encryptionKey);
105104

106105
const lgClient = createLangGraphClient({
107106
includeApiKey: true,
108-
defaultHeaders: {
107+
defaultHeaders: {
109108
[GITHUB_PAT]: encryptedGitHubToken,
110-
[GITHUB_INSTALLATION_ID]: githubInstallationId,
111109
},
112110
});
113111

@@ -165,6 +163,10 @@ async function runOpenSWEWithStreamTracking(inputs: {
165163
plannerRun = await withRetry(() =>
166164
lgClient.runs.join(plannerSession.threadId, plannerSession.runId),
167165
);
166+
167+
logger.info("Agent joined planner session", {
168+
plannerSession,
169+
});
168170
} catch (error) {
169171
logger.error("Error joining planner run", {
170172
thread_id: threadId,
@@ -192,6 +194,10 @@ async function runOpenSWEWithStreamTracking(inputs: {
192194
return result; // instead of skipping, we should award 0 points
193195
}
194196

197+
logger.info("Agent joined programmer session", {
198+
programmerSession,
199+
});
200+
195201
let programmerRun;
196202
try {
197203
programmerRun = await withRetry(() =>
@@ -231,8 +237,8 @@ async function runOpenSWEWithStreamTracking(inputs: {
231237
result.managerRunId = (managerRun as any).run_id;
232238
result.plannerRunId = plannerSession.runId;
233239
result.programmerRunId = programmerSession.runId;
240+
result.branchName = branchName;
234241
result.success = true;
235-
236242
} catch (error) {
237243
result.error = error instanceof Error ? error.message : String(error);
238244
logger.error("Open-swe stream tracking failed", {
@@ -312,30 +318,28 @@ async function processPR(prData: PRData): Promise<PRProcessResult> {
312318
logger.info("Starting open-swe...");
313319
const openSWEResults = await runOpenSWEWithStreamTracking({
314320
repoOwner: prData.repoOwner,
315-
repoName: prData.repoName,
321+
repoName: prData.repoName,
316322
baseCommit: preMergeCommit,
317323
userInput: createPRFixPrompt(prData),
318324
});
319325
result.openSWEResults = openSWEResults;
320326

321-
// Checkout test files from the merge commit to get the updated test files
322-
if (testFiles.length > 0) {
327+
// Only proceed with test checkout and execution if open-swe was successful and created a branch
328+
if (
329+
openSWEResults.success &&
330+
openSWEResults.branchName &&
331+
testFiles.length > 0
332+
) {
323333
logger.info(
324-
`Checking out test files from merge commit: ${prData.mergeCommitSha}`,
334+
`Open-swe completed successfully with branch: ${openSWEResults.branchName}. Checking out test files from merge commit: ${prData.mergeCommitSha}`,
325335
);
326336
await checkoutFilesFromCommit({
327337
sandbox,
328338
repoDir,
329339
commitSha: prData.mergeCommitSha,
330340
filePaths: testFiles,
331341
});
332-
}
333342

334-
// Run tests on detected test files
335-
if (testFiles.length > 0) {
336-
logger.info(
337-
`Running pytest on ${testFiles.length} detected test files...`,
338-
);
339343
const testResults = await runPytestOnFiles({
340344
sandbox,
341345
testFiles,
@@ -345,13 +349,24 @@ async function processPR(prData: PRData): Promise<PRProcessResult> {
345349
result.testResults = testResults;
346350

347351
logger.info(`Test execution completed for PR #${prData.prNumber}`, {
352+
branchName: openSWEResults.branchName,
348353
totalTests: testResults.totalTests,
349354
passedTests: testResults.passedTests,
350355
failedTests: testResults.failedTests,
351356
success: testResults.success,
352357
});
353358
} else {
354-
logger.info(`No test files to run for PR #${prData.prNumber}`);
359+
if (!openSWEResults.success) {
360+
logger.info(
361+
`Open-swe failed for PR #${prData.prNumber}, skipping test execution`,
362+
);
363+
} else if (!openSWEResults.branchName) {
364+
logger.info(
365+
`No branch created by open-swe for PR #${prData.prNumber}, skipping test execution`,
366+
);
367+
} else if (testFiles.length === 0) {
368+
logger.info(`No test files found for PR #${prData.prNumber}`);
369+
}
355370
}
356371

357372
result.success = true;

apps/open-swe/langbench/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export function createPRFixPrompt(prData: PRData): string {
1212
The PR has the following test files:
1313
${prData.testFiles.join("\n")}
1414
`;
15-
}
15+
}

apps/open-swe/langbench/static/langgraph_prs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"html_url": "https://github.com/langchain-ai/langgraph/pull/809",
55
"diff_url": "https://github.com/langchain-ai/langgraph/pull/809.diff",
66
"patch_url": "https://github.com/langchain-ai/langgraph/pull/809.patch",
7-
"repo_owner": "langchain-ai",
7+
"repo_owner": "Palashio",
88
"repo_name": "langgraph",
99
"pr_number": 809,
1010
"merge_commit_sha": "8e611b42aa35a7032c81ad2fd264d3192d47c911",
@@ -15,4 +15,4 @@
1515
"pre_merge_commit_sha": "6ae59581643b51751731ae64c609a8bc21779714",
1616
"test_files": ["libs/langgraph/tests/test_pregel.py"]
1717
}
18-
]
18+
]

apps/open-swe/src/utils/github-tokens.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ export function getGitHubTokensFromConfig(config: GraphConfig): {
2424

2525
const isProd = process.env.NODE_ENV === "production";
2626

27-
const installationId = config.configurable[GITHUB_INSTALLATION_ID];
28-
if (!installationId) {
29-
throw new Error(
30-
`Missing required ${GITHUB_INSTALLATION_ID} in configuration.`,
31-
);
32-
}
33-
3427
const githubPat = getGitHubPatFromConfig(config.configurable, encryptionKey);
3528
if (githubPat && !isProd) {
3629
// check for PAT-only mode
3730
return {
3831
githubAccessToken: githubPat,
3932
githubInstallationToken: githubPat,
40-
installationId,
33+
installationId: config.configurable[GITHUB_INSTALLATION_ID] ?? "",
4134
};
4235
}
4336

37+
const installationId = config.configurable[GITHUB_INSTALLATION_ID];
38+
if (!installationId) {
39+
throw new Error(
40+
`Missing required ${GITHUB_INSTALLATION_ID} in configuration.`,
41+
);
42+
}
43+
4444
const encryptedGitHubToken = config.configurable[GITHUB_TOKEN_COOKIE];
4545
const encryptedInstallationToken =
4646
config.configurable[GITHUB_INSTALLATION_TOKEN_COOKIE];

apps/open-swe/src/utils/github/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ export async function getBranch({
579579
repo,
580580
branch: branchName,
581581
});
582-
582+
logger.info("Branch", {
583+
branch,
584+
});
583585
return branch;
584586
},
585587
githubInstallationToken,

0 commit comments

Comments
 (0)