Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/actions/active-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ export async function terminateActiveSession(sessionId: string): Promise<ActionR

// 3. 终止 Session
const { SessionManager } = await import("@/lib/session-manager");
const success = await SessionManager.terminateSession(sessionId);
const result = await SessionManager.terminateSession(sessionId);

if (!success) {
if (!result.markerOk) {
return {
ok: false,
error: "终止 Session 失败(Redis 不可用或 Session 已过期)",
Expand Down
11 changes: 10 additions & 1 deletion src/app/v1/_lib/proxy/session-guard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getCachedSystemSettings } from "@/lib/config";
import { logger } from "@/lib/logger";
import { resolveKeyUserConcurrentSessionLimits } from "@/lib/rate-limit/concurrent-session-limit";
import { SessionManager } from "@/lib/session-manager";
import { SessionManager, TerminatedSessionError } from "@/lib/session-manager";
import { SessionTracker } from "@/lib/session-tracker";
import { completeCodexSessionIdentifiers } from "../codex/session-completer";
import { ProxyError } from "./errors";
import type { ProxySession } from "./session";

/**
Expand Down Expand Up @@ -178,6 +179,14 @@ export class ProxySessionGuard {
`[ProxySessionGuard] Session assigned: ${sessionId}:${requestSequence} (key=${keyId}, messagesLength=${session.getMessagesLength()}, clientProvided=${!!clientSessionId})`
);
} catch (error) {
if (error instanceof TerminatedSessionError) {
logger.info("[ProxySessionGuard] Client session was terminated, blocking request", {
sessionId: error.sessionId,
terminatedAt: error.terminatedAt,
});
throw new ProxyError("Session 已被终止,请创建新的会话后重试", 410);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

硬编码中文字符串违反 i18n 规范。

"Session 已被终止,请创建新的会话后重试" 直接硬编码为中文,违反了项目要求支持 5 种语言(zh-CN、zh-TW、en、ja、ru)的 i18n 规范。需通过 i18n 系统提供该错误消息。

As per coding guidelines: "All user-facing strings must use i18n (5 languages supported: zh-CN, zh-TW, en, ja, ru). Never hardcode display text."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/v1/_lib/proxy/session-guard.ts` at line 187, The throw in
session-guard.ts uses a hardcoded Chinese message in new ProxyError(...);
replace that literal with an i18n lookup (e.g., use the project's translation
API to fetch key like "errors.session_terminated") and pass the resulting
localized string to ProxyError, and add the corresponding translations for
zh-CN, zh-TW, en, ja and ru to the i18n resource bundle; ensure any necessary
import or context (e.g., the i18n instance or translator function used elsewhere
in this module) is used so the error message is localized at throw time.

}

logger.error("[ProxySessionGuard] Failed to assign session:", error);
// 降级:生成新 session(不阻塞请求)
const fallbackSessionId = SessionManager.generateSessionId();
Expand Down
Loading
Loading