📂 fix: Reject Missing Deployment Skill Files Before Upload (#17876)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run

A deployment skill file deleted from a running instance stays registered, and
fs.createReadStream only reported the missing path as a stream error once the
multipart upload was already in flight, which aborted the whole batch. Open the
file first so ENOENT rejects the promise primeSkillFiles already inspects, and
log the relative path of any file whose stream could not be acquired.
This commit is contained in:
Marco Beretta 2026-11-07 00:51:45 +01:00 • committed by GitHub
parent eb1e3e63a2
commit 44eb8fea36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 117 additions and 3 deletions

View file

@ -14,6 +14,7 @@ jest.mock('./run', () => ({
import { Readable } from 'stream';
import { Types } from 'mongoose';
import { logger } from '@librechat/data-schemas';
import { createCodeApiUploadRegistry } from '~/utils';
import { primeInvokedSkills, primeInvokedSkillsForProfiles, primeSkillFiles } from './skillFiles';
import type {
@ -933,6 +934,51 @@ describe('primeSkillFiles — resource identity propagation', () => {
jest.clearAllMocks();
});
it('names the file whose stream failed and uploads the rest of the bundle', async () => {
const missingPathError = Object.assign(new Error('ENOENT: /srv/skills/secret/missing.dotx'), {
code: 'ENOENT',
});
const getDownloadStream = jest.fn(async (_req: unknown, filepath: string) => {
if (filepath.endsWith('missing.dotx')) {
throw missingPathError;
}
return Readable.from(Buffer.from('style'));
});
const deps = makeSkillFilesDeps({
skillFiles: [
{
relativePath: 'masters/missing.dotx',
filename: 'missing.dotx',
filepath: '/srv/skills/secret/missing.dotx',
source: 'deployment',
bytes: 16,
},
{
relativePath: 'references/style.md',
filename: 'style.md',
filepath: '/srv/skills/secret/style.md',
source: 'deployment',
bytes: 5,
},
],
getStrategyFunctions: jest.fn().mockReturnValue({ getDownloadStream }),
});
const result = await primeSkillFiles(deps);
const { files } = (deps.batchUploadCodeEnvFiles as jest.Mock).mock.calls[0][0];
expect(files.map((file: { filename: string }) => file.filename)).toEqual([
'skills/brand-guidelines/SKILL.md',
'skills/brand-guidelines/references/style.md',
]);
expect(result?.storage_session_id).toBe('session-fresh');
expect(logger.error).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledWith('[primeSkillFiles] Failed to get stream:', {
relativePath: 'masters/missing.dotx',
type: 'Error',
});
});
it('fresh-upload path: emits resource_id=skill._id, kind=skill, version on each file', async () => {
const deps = makeSkillFilesDeps({
skillFiles: [

View file

@ -244,11 +244,14 @@ async function collectSkillUploadFiles(
}
signal.throwIfAborted();
}
for (const result of streamResults) {
for (const [index, result] of streamResults.entries()) {
if (result.status === 'fulfilled' && result.value) {
filesToUpload.push(result.value);
} else if (result.status === 'rejected') {
logger.error('[primeSkillFiles] Failed to get stream:', getSafeErrorMetadata(result.reason));
logger.error('[primeSkillFiles] Failed to get stream:', {
relativePath: skillFiles[index].relativePath,
...getSafeErrorMetadata(result.reason),
});
}
}

View file

@ -8,6 +8,7 @@ import type { DeploymentSkillBaseMethods } from '../deployment';
import {
DEPLOYMENT_SKILLS_DIR_ENV,
createDeploymentSkillMethods,
getDeploymentSkillDownloadStream,
getDeploymentSkillIds,
initializeDeploymentSkills,
loadDeploymentSkillsFromDirectory,
@ -102,6 +103,67 @@ describe('resolveDeploymentSkillDirectory', () => {
});
});
describe('getDeploymentSkillDownloadStream', () => {
async function loadGuide(): Promise<string> {
const root = await makeTempRoot();
const skillDir = await writeDeploymentSkill(root);
await initializeDeploymentSkills({ projectRoot: root, env: {} });
return path.join(skillDir, 'references', 'guide.txt');
}
it('streams a registered file that still exists', async () => {
const guide = await loadGuide();
const stream = await getDeploymentSkillDownloadStream(guide);
const chunks: Buffer[] = [];
for await (const chunk of stream) {
chunks.push(Buffer.from(chunk));
}
expect(Buffer.concat(chunks).toString('utf8')).toBe('reference notes');
});
it('rejects when a registered file was deleted after the registry loaded', async () => {
const guide = await loadGuide();
await fs.promises.rm(guide);
await expect(getDeploymentSkillDownloadStream(guide)).rejects.toMatchObject({
code: 'ENOENT',
});
});
it('rejects a path the registry does not know', async () => {
const guide = await loadGuide();
await expect(getDeploymentSkillDownloadStream(`${guide}.unregistered`)).rejects.toThrow(
'Deployment skill file is not registered',
);
});
it('keeps serving a file deleted after its stream was opened', async () => {
const guide = await loadGuide();
const stream = await getDeploymentSkillDownloadStream(guide);
await fs.promises.rm(guide);
const chunks: Buffer[] = [];
for await (const chunk of stream) {
chunks.push(Buffer.from(chunk));
}
expect(Buffer.concat(chunks).toString('utf8')).toBe('reference notes');
});
it('closes the file when the stream is destroyed before it is read', async () => {
const guide = await loadGuide();
const stream = (await getDeploymentSkillDownloadStream(guide)) as fs.ReadStream;
const closed = new Promise<void>((resolve) => stream.once('close', () => resolve()));
stream.destroy();
await expect(closed).resolves.toBeUndefined();
});
});
describe('loadDeploymentSkillsFromDirectory', () => {
it('treats a missing default directory as an empty deployment catalog', async () => {
const root = await makeTempRoot();

View file

@ -392,7 +392,10 @@ export async function getDeploymentSkillDownloadStream(
if (!registry.hasFilePath(filepath)) {
throw new Error('Deployment skill file is not registered');
}
return fs.createReadStream(filepath);
/* The registry outlives the files it lists, and `fs.createReadStream` only reports a
* missing path as a stream error once a consumer is reading. Opening first rejects here. */
const handle = await fs.promises.open(filepath, 'r');
return handle.createReadStream();
}
export function resolveDeploymentSkillDirectory(