Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): log where and how a generated file failed to attach
marcotebfb8cbfef7e86
diff --git a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.tsindex 5846bc302..db64cb950 100644--- a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts+++ b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts@@ -876,6 +876,37 @@ describe('generated internal artifact attachments', () => {})})+ it.skipIf(process.getuid?.() === 0)(+ 'logs the stage, name and code of a read that fails, not only that it failed',+ async () => {+ const { logger } = await import('../../../logger')+ const warn = vi.spyOn(logger, 'warn')+ fs.writeFileSync(path.join(outputDir, 'locked.md'), '# locked\n')+ fs.chmodSync(path.join(outputDir, 'locked.md'), 0o000)+ try {+ const attachment = buildGeneratedArtifactAttachment({+ sourceTool: 'clerum__generate_markdown',+ artifact: metadata(outputDir, 'locked.md', 'md'),+ outputDir,+ maxBytes: 1024,+ })+ expect(attachment).toBeNull()+ expect(warn).toHaveBeenCalledWith(+ expect.objectContaining({+ reason: 'artifact_path_error_500',+ stage: 'open',+ errorName: 'ArtifactPathError',+ errorCode: 'EACCES',+ }),+ 'Skipping artifact attachment'+ )+ } finally {+ fs.chmodSync(path.join(outputDir, 'locked.md'), 0o600)+ warn.mockRestore()+ }+ }+ )+it('native internal tools return generated artifact attachments through the adapter', async () => {const config: NativeToolConfig = {workspacePath: outputDir,diff --git a/mcp-host/src/core/tools/generatedArtifactAttachments.ts b/mcp-host/src/core/tools/generatedArtifactAttachments.tsindex d7a636d03..01483cbef 100644--- a/mcp-host/src/core/tools/generatedArtifactAttachments.ts+++ b/mcp-host/src/core/tools/generatedArtifactAttachments.ts@@ -114,7 +114,12 @@ function closeFd(fd: number): void {}}-function warnSkip(reason: string, sourceTool: string, artifact: ArtifactMetadata): void {+function warnSkip(+ reason: string,+ sourceTool: string,+ artifact: ArtifactMetadata,+ failure?: { stage: string; errorName?: string; errorCode?: string }+): void {logger.warn({component: 'GeneratedArtifactAttachment',@@ -122,6 +127,7 @@ function warnSkip(reason: string, sourceTool: string, artifact: ArtifactMetadatatool: sourceTool,format: artifact.format,filename: artifact.name,+ ...failure,},'Skipping artifact attachment')@@ -260,9 +266,13 @@ export function buildGeneratedArtifactAttachment(}let opened+ // Where an unexpected error stopped the delivery, for the log.+ let stage: 'open' | 'read' | 'check' | 'redact' = 'open'try {opened = openExistingArtifactFile(params.outputDir, params.artifact.name)+ stage = 'read'const fileBuffer = readOpenedArtifactBuffer(opened, params.maxBytes)+ stage = 'check'if (params.writtenSha256 !== undefined &&createHash('sha256').update(fileBuffer).digest('hex') !== params.writtenSha256@@ -334,7 +344,9 @@ export function buildGeneratedArtifactAttachment(return null}}+ stage = 'redact'const redacted = redactArtifactForDelivery(expectedFormat, fileBuffer, secretEntries)+ stage = 'check'// A value printed whole once is redacted, but the same value split by// markup elsewhere in the file is not: read the redacted text as printed.if (@@ -370,7 +382,13 @@ export function buildGeneratedArtifactAttachment(} catch (err) {const reason =err instanceof ArtifactPathError ? `artifact_path_error_${err.status}` : 'artifact_read_error'- warnSkip(reason, params.sourceTool, params.artifact)+ // The name and code say what failed; the message may hold a path, so it is left out.+ const code = (err as NodeJS.ErrnoException | ArtifactPathError | undefined)?.code+ warnSkip(reason, params.sourceTool, params.artifact, {+ stage,+ errorName: err instanceof Error ? err.name : typeof err,+ ...(typeof code === 'string' ? { errorCode: code } : {}),+ })return null} finally {if (opened) closeFd(opened.fd)diff --git a/mcp-host/src/workflow/artifactPaths.ts b/mcp-host/src/workflow/artifactPaths.tsindex a7f286f88..b597e130a 100644--- a/mcp-host/src/workflow/artifactPaths.ts+++ b/mcp-host/src/workflow/artifactPaths.ts@@ -9,7 +9,9 @@ export const MAX_ARTIFACT_BYTES = 50 * 1024 * 1024export class ArtifactPathError extends Error {constructor(readonly status: 400 | 403 | 404 | 413 | 500,- message: string+ message: string,+ /** The filesystem error code behind it, for logs; never sent to a caller. */+ readonly code?: string) {super(message)this.name = 'ArtifactPathError'@@ -43,7 +45,7 @@ function artifactFsError(err: unknown): ArtifactPathError {if (code === 'ELOOP') {return new ArtifactPathError(403, 'Symlink artifacts are not allowed')}- return new ArtifactPathError(500, 'Failed to read artifact')+ return new ArtifactPathError(500, 'Failed to read artifact', code)}function resolveArtifactCandidate(outputDir: string, filename: string): ArtifactCandidate {