fix(aia,ssa,asl,infra): harden SSE transport and stabilize attachment context

Deliver SSE protocol hardening for SAE/HTTP2 paths, add graceful shutdown health behavior, and improve SSA retry UX for transient stream failures. For AIA, persist attachment extraction results in database with cache read-through fallback, plus production cache safety guard to prevent memory-cache drift in multi-instance deployments; also restore ASL SR page scrolling behavior.

Made-with: Cursor
This commit is contained in:
2026-03-09 18:45:12 +08:00
parent 50657dd81f
commit 5c5fec52c1
27 changed files with 807 additions and 100 deletions

View File

@@ -15,7 +15,7 @@ import { aslRoutes } from './modules/asl/routes/index.js';
import { registerDCRoutes, initDCModule } from './modules/dc/index.js';
import pkbRoutes from './modules/pkb/routes/index.js';
import { aiaRoutes } from './modules/aia/index.js';
import { registerHealthRoutes } from './common/health/index.js';
import { registerHealthRoutes, markShuttingDown } from './common/health/index.js';
import { logger } from './common/logging/index.js';
import { authRoutes, registerAuthPlugin } from './common/auth/index.js';
import { promptRoutes } from './common/prompt/index.js';
@@ -339,11 +339,24 @@ start();
// ============================================
// 🛡️ 优雅关闭处理Graceful Shutdown
// ============================================
const SHUTDOWN_TIMEOUT_MS = 30_000;
const gracefulShutdown = async (signal: string) => {
console.log(`\n⚠ 收到 ${signal} 信号,开始优雅关闭...`);
// 立即标记停机,健康检查返回 503CLB 不再派发新请求
markShuttingDown();
console.log('🚫 健康检查已切换为 503CLB 将停止路由新流量');
// 强制超时兜底:防止 SSE 长连接或死循环任务阻塞退出
const forceTimer = setTimeout(() => {
console.error(`❌ 优雅关闭超时 (${SHUTDOWN_TIMEOUT_MS / 1000}s),强制退出`);
process.exit(1);
}, SHUTDOWN_TIMEOUT_MS);
forceTimer.unref();
try {
// 1. 停止接收新请求
// 1. 停止接收新请求(已有 SSE 连接继续跑完)
await fastify.close();
console.log('✅ HTTP 服务已停止');