fix(files): S-6 identify goes through the shared TMDB limiter and caps remote queries

- invoke-limits: sharedInvokeLimiter() (one semaphore set per process); agent
  capability routes default to it
- /files/identify: catalog.lookup with includeRemote runs under the shared
  TMDB semaphore + 15s timeout; at most 20 distinct remote queries per
  request, further items fall back to local recall with a warning

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-28 00:48:45 +08:00
1 parent ba1361a9b6
commit b4560be48b
4 files changed
+49 -8

No files matched your search

@@ -137,3 +137,13 @@ export function createInvokeLimiter(
},
};
}
let shared: InvokeLimiter | null = null;
/**
* 进程内共享的限流器:同一 API 进程里所有 HTTP 路径上的外部 IO 调用(能力调用端点、/files/identify 等)
* 共用同一组信号量,TMDB/站点并发上限才是真正的进程级上限(验收 07 S-6)。
*/
export function sharedInvokeLimiter(): InvokeLimiter {
shared ??= createInvokeLimiter();
return shared;
}
+2 -2
View File
@@ -14,7 +14,7 @@ import type { ModuleApp, ServerContext } from "../types.ts";
import { planBinding } from "./authorize.ts";
import { cancelTask, retryTask, taskToApi } from "./capabilities.ts";
import { route } from "./http.ts";
import { createInvokeLimiter, type InvokeLimiter, UpstreamBusyError, UpstreamTimeoutError } from "./invoke-limits.ts";
import { type InvokeLimiter, sharedInvokeLimiter, UpstreamBusyError, UpstreamTimeoutError } from "./invoke-limits.ts";
import { AgentRunError, abortRun, appendMessage, startRun } from "./service.ts";
// Agent 会话 API、持续授权 / 单次审批、能力目录与调用、业务任务。
@@ -89,7 +89,7 @@ const decode = (c?: string) => {
export function registerAgentRoutes(
app: ModuleApp,
ctx: ServerContext,
limiter: InvokeLimiter = createInvokeLimiter(),
limiter: InvokeLimiter = sharedInvokeLimiter(),
) {
const db = () => ctx.db;