🥼 feat: Expose BYOM Cancellation Diagnostics (#15810)

* Trace BYOM command cancellation at the HTTP boundary

* 🧹 chore: Sort Command Module Imports

The Static Checks job fails on this branch at the "Import sorting" step:
`node scripts/sort-imports.mts --check` reports
`packages/api/src/code/command.ts` as out of order.

The `logger` import added for the BYOM command diagnostics was placed after
`import { tool } from '@librechat/agents/langchain/tools'`, but package
imports sort shortest to longest line, and the data-schemas import is the
shorter of the two. Reordered by running the repo's own sorter, which is
also what the pre-commit lint-staged hook applies.
This commit is contained in:
Danny Avila 2026-09-10 15:16:20 -04:00 • committed by GitHub
parent e49cb798da
commit bee183e6a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 139 additions and 18 deletions

View file

@ -66,6 +66,50 @@ function commandResponse(overrides: Record<string, unknown> = {}): Response {
}
describe('createAttachedWorkspaceBashTool', () => {
test('disconnects the actual HTTP request when an invoked command is cancelled', async () => {
let markStarted!: () => void;
let markDisconnected!: () => void;
const started = new Promise<void>((resolve) => {
markStarted = resolve;
});
const disconnected = new Promise<void>((resolve) => {
markDisconnected = resolve;
});
const server = createServer(async (req, res) => {
for await (const _chunk of req) {
/* Consume the complete request before cancellation. */
}
res.once('close', () => {
if (!res.writableEnded) markDisconnected();
});
markStarted();
});
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const { port } = server.address() as AddressInfo;
const bashTool = createAttachedWorkspaceBashTool({
baseUrl: `http://127.0.0.1:${port}/v1`,
authHeaders: () => ({}),
workspaceId: 'project-a',
});
const controller = new AbortController();
try {
const invocation = bashTool.invoke({ command: 'sleep 30' }, { signal: controller.signal });
const settled = invocation.then(
() => ({ rejected: false }),
() => ({ rejected: true }),
);
await started;
controller.abort();
expect((await settled).rejected).toBe(true);
await disconnected;
} finally {
server.closeAllConnections();
server.close();
await once(server, 'close');
}
});
test('executes in the selected workspace and relative working directory', async () => {
const fetchImpl: CodeBridgeFetch = jest.fn(async () => commandResponse());
const authHeaders = jest.fn().mockResolvedValue({