mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 13:33:45 +00:00
🎟️ fix: Preserve BYOM Tool Calls Through Capacity Windows (#16060)
* ⏳ fix: Keep BYOM tools queued across capacity windows * ⏳ fix: Configure the admission budget and refresh queued credentials Addresses the Codex review on #16060: - Add `limits.maxQueueWaitMs` to the code environment config schema so a deployment can shorten or disable the five-minute admission budget from `librechat.yaml`; omission keeps the merged behavior, `0` surfaces the first capacity expiry to the model. Resolved through `resolveAttachedWorkspaceQueueWaitMs` and passed by ToolService, matching how `maxCommandTimeoutMs` already flows. - Accept an auth-header supplier in `executeWorkspaceTool` and mint it per admission attempt, so a call queued past the Code API token TTL presents fresh credentials instead of failing permanently with 401. The attached Bash tool and the workspace file operations now pass suppliers. - Recheck the deadline after a clamped wait and throw the saved rejection rather than opening an admission window that could still be admitted once the budget is spent. * fix: Complete workspace admission wiring and caller regressions * fix: Share protected edit retry budgets and schema limits --------- Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
c821638e3d
commit
c0affede00
12 changed files with 739 additions and 155 deletions
|
|
@ -19,6 +19,7 @@ import {
|
|||
executeWorkspaceTool,
|
||||
WORKSPACE_COMMAND_DEFAULT_TIMEOUT_MS,
|
||||
WORKSPACE_COMMAND_MAX_TIMEOUT_MS,
|
||||
WORKSPACE_QUEUE_MAX_WAIT_MS,
|
||||
} from './workspace';
|
||||
|
||||
const DEFAULT_OUTPUT_BYTES = 256 * 1024;
|
||||
|
|
@ -93,6 +94,21 @@ export function resolveAttachedWorkspaceCommandTimeoutMax(
|
|||
: normalizeAttachedWorkspaceCommandTimeoutMax(configured);
|
||||
}
|
||||
|
||||
/**
|
||||
* Client retry horizon for one capacity-blocked invocation. `0` surfaces the
|
||||
* first capacity expiry without retrying; an in-flight server admission window
|
||||
* and execution retain their own budgets.
|
||||
*/
|
||||
export function resolveAttachedWorkspaceQueueWaitMs(
|
||||
configSchema?: CodeEnvironmentUserConfigSchema,
|
||||
): number {
|
||||
const configured = configSchema?.limits?.maxQueueWaitMs;
|
||||
if (configured == null || !Number.isSafeInteger(configured) || configured < 0) {
|
||||
return WORKSPACE_QUEUE_MAX_WAIT_MS;
|
||||
}
|
||||
return Math.min(WORKSPACE_QUEUE_MAX_WAIT_MS, configured);
|
||||
}
|
||||
|
||||
export function buildAttachedWorkspaceBashSchema(
|
||||
maxTimeoutMs: number = WORKSPACE_COMMAND_DEFAULT_TIMEOUT_MS,
|
||||
environment?: CodeWorkspaceDescriptor['environment'],
|
||||
|
|
@ -235,6 +251,7 @@ export function createAttachedWorkspaceBashTool({
|
|||
environment,
|
||||
gitIdentity,
|
||||
maxTimeoutMs = WORKSPACE_COMMAND_DEFAULT_TIMEOUT_MS,
|
||||
maxQueueWaitMs,
|
||||
fetchImpl,
|
||||
}: {
|
||||
baseUrl: string;
|
||||
|
|
@ -244,6 +261,8 @@ export function createAttachedWorkspaceBashTool({
|
|||
gitIdentity?: AgentGitIdentity | null;
|
||||
/** Deployment ceiling already intersected with the protocol hard cap. */
|
||||
maxTimeoutMs?: number;
|
||||
/** Deployment admission budget; omitted keeps the built-in default. */
|
||||
maxQueueWaitMs?: number;
|
||||
fetchImpl?: CodeBridgeFetch;
|
||||
}): DynamicStructuredTool {
|
||||
const effectiveMaxTimeoutMs = normalizeAttachedWorkspaceCommandTimeoutMax(maxTimeoutMs);
|
||||
|
|
@ -301,7 +320,8 @@ export function createAttachedWorkspaceBashTool({
|
|||
try {
|
||||
const result = await executeWorkspaceTool({
|
||||
baseURL: baseUrl,
|
||||
authHeaders: await authHeaders(),
|
||||
/** Passed as a supplier: a queued call outlives its minted token. */
|
||||
authHeaders,
|
||||
request: {
|
||||
protocolVersion: 1,
|
||||
operation: 'execute_command',
|
||||
|
|
@ -316,6 +336,7 @@ export function createAttachedWorkspaceBashTool({
|
|||
},
|
||||
signal,
|
||||
fetchImpl,
|
||||
...(maxQueueWaitMs == null ? {} : { maxQueueWaitMs }),
|
||||
});
|
||||
if (result.operation !== 'execute_command') {
|
||||
throw new Error('Attached workspace returned an unexpected command result.');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue