🧹 chore: Remove diagnostic logs from code-files seeding path

Drops the temporary debug logs added to trace the empty-tool_resources
failure mode. Production code paths (loadToolDefinitionsWrapper,
client.js seed loop, initializeAgent file lookup) are left as the
permanent shape: capture primedCodeFiles, merge across agents, seed
initialSessions before run start.
This commit is contained in:
Danny Avila 2026-04-26 15:06:37 -04:00
parent c2a0a660b7
commit 1e055949a9
3 changed files with 3 additions and 89 deletions

View file

@ -838,20 +838,10 @@ class AgentClient extends BaseClient {
...(this.agentConfigs ? this.agentConfigs.values() : []),
];
for (const a of agentsToSeed) {
logger.debug('[AgentClient] seed pass for agent', {
agentId: a?.id,
primedCodeFilesCount: a?.primedCodeFiles?.length ?? 0,
hasPrimedCodeFilesField: 'primedCodeFiles' in (a ?? {}),
codeEnvAvailable: a?.codeEnvAvailable,
});
if (a?.primedCodeFiles?.length) {
initialSessions = seedCodeFilesIntoSessions(a.primedCodeFiles, initialSessions);
}
}
logger.debug('[AgentClient] final initialSessions for createRun', {
hasMap: !!initialSessions,
executeCodeEntryFiles: initialSessions?.get?.('execute_code')?.files?.length ?? 0,
});
let {
messages: initialMessages,

View file

@ -795,13 +795,6 @@ async function loadToolDefinitionsWrapper({ req, res, agent, streamId = null, to
* sandbox can't see the prior turn's generated artifacts on first read.
*/
let primedCodeFiles;
logger.debug('[loadToolDefinitionsWrapper] code-files prime check', {
agentId: agent.id,
hasExecuteCode,
toolResourceKeys: Object.keys(tool_resources ?? {}),
codeFileIdCount: tool_resources?.[EToolResources.execute_code]?.file_ids?.length ?? 0,
codeFileObjCount: tool_resources?.[EToolResources.execute_code]?.files?.length ?? 0,
});
if (hasExecuteCode && tool_resources) {
try {
const { toolContext, files } = await primeCodeFiles({
@ -815,13 +808,6 @@ async function loadToolDefinitionsWrapper({ req, res, agent, streamId = null, to
if (files?.length) {
primedCodeFiles = files;
}
logger.debug('[loadToolDefinitionsWrapper] primeCodeFiles result', {
agentId: agent.id,
primedCount: files?.length ?? 0,
sample: (files ?? [])
.slice(0, 3)
.map((f) => ({ id: f.id, session_id: f.session_id, name: f.name })),
});
} catch (error) {
logger.error('[loadToolDefinitionsWrapper] Error priming code files:', error);
}

View file

@ -399,10 +399,10 @@ export async function initializeAgent(
let codeGeneratedFiles: IMongoFile[] = [];
let userCodeFiles: IMongoFile[] = [];
let threadMessageIds: string[] | undefined;
let threadFileIds: string[] | undefined;
if (toolResourceSet.has(EToolResources.execute_code)) {
let threadMessageIds: string[] | undefined;
let threadFileIds: string[] | undefined;
if (parentMessageId && parentMessageId !== Constants.NO_PARENT && db.getMessages) {
/** Only select fields needed for thread traversal */
const messages = await db.getMessages(
@ -431,74 +431,12 @@ export async function initializeAgent(
}
}
logger.debug('[initializeAgent] code-files lookup', {
agentId: agent.id,
conversationId,
parentMessageId,
resendFiles,
agentToolStrings: (agent.tools ?? []).filter((t): t is string => typeof t === 'string'),
toolResourceSetHasExecCode: toolResourceSet.has(EToolResources.execute_code),
convoFileIdCount: fileIds.length,
toolFileCount: toolFiles.length,
threadMsgCount: threadMessageIds?.length ?? 0,
threadFileIdCount: threadFileIds?.length ?? 0,
threadMessageIdsSample: (threadMessageIds ?? []).slice(0, 5),
codeGeneratedFileCount: codeGeneratedFiles.length,
userCodeFileCount: userCodeFiles.length,
});
/**
* Sanity probe: when the thread covers a parent message and yet
* `getCodeGeneratedFiles` returned 0, run a relaxed lookup for the
* same conversation+context and report what's actually in the DB —
* this isolates whether the messageId filter is the culprit vs. the
* file simply not existing under this conversation/context.
*/
if (
toolResourceSet.has(EToolResources.execute_code) &&
codeGeneratedFiles.length === 0 &&
(threadMessageIds?.length ?? 0) > 0 &&
db.getFiles
) {
try {
const probeFiles = (await db.getFiles(
{ conversationId, context: 'execute_code' },
{},
{ messageId: 1, file_id: 1, filename: 1, 'metadata.fileIdentifier': 1, _id: 0 },
)) as Array<{
messageId?: string;
file_id?: string;
filename?: string;
metadata?: { fileIdentifier?: string };
}>;
logger.debug('[initializeAgent] code-files probe (no messageId filter)', {
agentId: agent.id,
probeCount: probeFiles.length,
sample: probeFiles.slice(0, 5).map((f) => ({
messageId: f.messageId,
file_id: f.file_id,
filename: f.filename,
hasFileIdentifier: !!f.metadata?.fileIdentifier,
})),
});
} catch (probeError) {
logger.warn('[initializeAgent] code-files probe failed', probeError);
}
}
const allToolFiles = toolFiles.concat(codeGeneratedFiles, userCodeFiles);
if (requestFiles.length || allToolFiles.length) {
currentFiles = (await db.updateFilesUsage(requestFiles.concat(allToolFiles))) as IMongoFile[];
}
} else if (requestFiles.length) {
currentFiles = (await db.updateFilesUsage(requestFiles)) as IMongoFile[];
} else {
logger.debug('[initializeAgent] code-files lookup skipped', {
agentId: agent.id,
hasConversationId: conversationId != null,
resendFiles,
requestFileCount: requestFiles.length,
});
}
if (currentFiles && currentFiles.length) {