Skip to content

Commit 03db2d8

Browse files
committed
fix: address code review feedback
- Remove unused files variable in relabelUsingFullFilesForUser - Add error logging for rejected relabel promises - Extract FULL_FILE_CONTEXT_SUFFIX constant - Add warning logging when SDK agent loading fails - Improve API key error message with details and hint
1 parent b102618 commit 03db2d8

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

cli/src/utils/local-agent-registry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { loadLocalAgents as sdkLoadLocalAgents } from '@codebuff/sdk'
66

77
import { getProjectRoot } from '../project-files'
88
import { AGENT_MODE_TO_ID, type AgentMode } from './constants'
9+
import { logger } from './logger'
910

1011
import type { AgentDefinition } from '@codebuff/common/templates/initial-agents-dir/types/agent-definition'
1112

@@ -42,8 +43,9 @@ export async function initializeAgentRegistry(): Promise<void> {
4243
userAgentsCache = await sdkLoadLocalAgents({ agentsPath: agentsDir })
4344
// Build ID-to-filepath map by scanning agent files
4445
userAgentFilePaths = buildAgentFilePathMap(agentsDir)
45-
} catch {
46-
// Fall back to empty cache if SDK loading fails
46+
} catch (error) {
47+
// Fall back to empty cache if SDK loading fails, but log a warning
48+
logger.warn({ error, agentsDir }, 'Failed to load user agents from .agents directory')
4749
userAgentsCache = {}
4850
userAgentFilePaths = new Map()
4951
}

web/src/app/api/admin/relabel-for-user/route.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type { NextRequest } from 'next/server'
3232

3333
const STATIC_SESSION_ID = 'relabel-trace-api'
3434
const DEFAULT_RELABEL_LIMIT = 10
35+
const FULL_FILE_CONTEXT_SUFFIX = '-with-full-file-context'
3536
const modelsToRelabel = [
3637
finetunedVertexModels.ft_filepicker_008,
3738
finetunedVertexModels.ft_filepicker_topk_002,
@@ -102,7 +103,11 @@ export async function POST(req: NextRequest) {
102103
const apiKey = env.CODEBUFF_API_KEY
103104
if (!apiKey) {
104105
return NextResponse.json(
105-
{ error: 'CODEBUFF_API_KEY is not configured. This env var is required for relabeling operations.' },
106+
{
107+
error: 'CODEBUFF_API_KEY is not configured',
108+
details: 'This endpoint now calls LLMs directly (backend was removed) and requires CODEBUFF_API_KEY to be set.',
109+
hint: 'Add CODEBUFF_API_KEY to your environment variables. See .env.example for reference.',
110+
},
106111
{ status: 500 },
107112
)
108113
}
@@ -249,14 +254,11 @@ async function relabelUsingFullFilesForUser(params: {
249254

250255
for (const traceBundle of tracesBundles) {
251256
const trace = traceBundle.trace as GetRelevantFilesTrace
252-
const files = traceBundle.relatedTraces.find(
253-
(t) => t.type === 'get-expanded-file-context-for-training',
254-
) as GetExpandedFileContextForTrainingTrace | undefined
255257
const fileBlobs = traceBundle.relatedTraces.find(
256258
(t) => t.type === 'get-expanded-file-context-for-training-blobs',
257259
) as GetExpandedFileContextForTrainingBlobTrace | undefined
258260

259-
if (!files || !fileBlobs) {
261+
if (!fileBlobs) {
260262
continue
261263
}
262264

@@ -277,7 +279,7 @@ async function relabelUsingFullFilesForUser(params: {
277279
]) {
278280
if (
279281
!traceBundle.relabels.some(
280-
(r) => r.model === `${model}-with-full-file-context`,
282+
(r) => r.model === `${model}${FULL_FILE_CONTEXT_SUFFIX}`,
281283
)
282284
) {
283285
relabelPromises.push(
@@ -302,7 +304,14 @@ async function relabelUsingFullFilesForUser(params: {
302304
}
303305
}
304306

305-
await Promise.allSettled(relabelPromises)
307+
const results = await Promise.allSettled(relabelPromises)
308+
309+
// Log any failures from parallel relabeling
310+
for (const result of results) {
311+
if (result.status === 'rejected') {
312+
logger.error({ error: result.reason }, 'Relabeling task failed')
313+
}
314+
}
306315

307316
return relabeled
308317
}
@@ -425,7 +434,7 @@ async function relabelWithClaudeWithFullFileContext(params: {
425434
agent_step_id: trace.agent_step_id,
426435
user_id: trace.user_id,
427436
created_at: new Date(),
428-
model: `${model}-with-full-file-context`,
437+
model: `${model}${FULL_FILE_CONTEXT_SUFFIX}`,
429438
payload: {
430439
user_input_id: tracePayload.user_input_id,
431440
client_session_id: tracePayload.client_session_id,

0 commit comments

Comments
 (0)