Skip to content

Commit cee5e31

Browse files
cursoragentmsukkari
andcommitted
fix: use lazy evaluation for REVIEW_AGENT_LOG_DIR to fix build
Change REVIEW_AGENT_LOG_DIR from a top-level constant to a getReviewAgentLogDir() function to avoid evaluating env.DATA_CACHE_DIR at module load time, which fails during Next.js build when environment variables are not yet available. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
1 parent f887d91 commit cee5e31

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/web/src/features/agents/review-agent/app.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Octokit } from "octokit";
22
import { generatePrReviews } from "@/features/agents/review-agent/nodes/generatePrReview";
33
import { githubPushPrReviews } from "@/features/agents/review-agent/nodes/githubPushPrReviews";
44
import { githubPrParser } from "@/features/agents/review-agent/nodes/githubPrParser";
5-
import { REVIEW_AGENT_LOG_DIR } from "@/features/agents/review-agent/nodes/invokeDiffReviewLlm";
5+
import { getReviewAgentLogDir } from "@/features/agents/review-agent/nodes/invokeDiffReviewLlm";
66
import { env } from "@sourcebot/shared";
77
import { GitHubPullRequest } from "@/features/agents/review-agent/types";
88
import path from "path";
@@ -31,8 +31,9 @@ export async function processGitHubPullRequest(octokit: Octokit, pullRequest: Gi
3131

3232
let reviewAgentLogPath: string | undefined;
3333
if (env.REVIEW_AGENT_LOGGING_ENABLED) {
34-
if (!fs.existsSync(REVIEW_AGENT_LOG_DIR)) {
35-
fs.mkdirSync(REVIEW_AGENT_LOG_DIR, { recursive: true });
34+
const reviewAgentLogDir = getReviewAgentLogDir();
35+
if (!fs.existsSync(reviewAgentLogDir)) {
36+
fs.mkdirSync(reviewAgentLogDir, { recursive: true });
3637
}
3738

3839
const timestamp = new Date().toLocaleString('en-US', {
@@ -44,7 +45,7 @@ export async function processGitHubPullRequest(octokit: Octokit, pullRequest: Gi
4445
second: '2-digit',
4546
hour12: false
4647
}).replace(/(\d+)\/(\d+)\/(\d+), (\d+):(\d+):(\d+)/, '$3_$1_$2_$4_$5_$6');
47-
reviewAgentLogPath = path.join(REVIEW_AGENT_LOG_DIR, `review-agent-${pullRequest.number}-${timestamp}.log`);
48+
reviewAgentLogPath = path.join(reviewAgentLogDir, `review-agent-${pullRequest.number}-${timestamp}.log`);
4849
logger.info(`Review agent logging to ${reviewAgentLogPath}`);
4950
}
5051

packages/web/src/features/agents/review-agent/nodes/invokeDiffReviewLlm.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { createLogger } from "@sourcebot/shared";
77

88
const logger = createLogger('invoke-diff-review-llm');
99

10-
export const REVIEW_AGENT_LOG_DIR = path.join(env.DATA_CACHE_DIR, 'review-agent');
10+
export const getReviewAgentLogDir = (): string => {
11+
return path.join(env.DATA_CACHE_DIR, 'review-agent');
12+
};
1113

1214
const validateLogPath = (logPath: string): void => {
1315
const resolved = path.resolve(logPath);
14-
if (!resolved.startsWith(REVIEW_AGENT_LOG_DIR + path.sep)) {
16+
const logDir = getReviewAgentLogDir();
17+
if (!resolved.startsWith(logDir + path.sep)) {
1518
throw new Error('reviewAgentLogPath escapes log directory');
1619
}
1720
};

0 commit comments

Comments
 (0)