fix clarify replay and compression timeout (#1044)

This commit is contained in:
ekko
2026-05-26 19:15:22 +08:00
committed by GitHub
parent e926a8e2fb
commit 82680f5c0b
7 changed files with 104 additions and 7 deletions
@@ -52,7 +52,7 @@ export interface CompressionConfig {
headMessageCount: number
/** Number of recent messages to keep verbatim (default: 10) */
tailMessageCount: number
/** Timeout for LLM summarization call (default: 60_000ms) */
/** Timeout for LLM summarization call (default: 300_000ms) */
summarizationTimeoutMs: number
}
@@ -61,7 +61,7 @@ export const DEFAULT_COMPRESSION_CONFIG: CompressionConfig = {
summaryBudget: 8_000,
headMessageCount: 0,
tailMessageCount: 10,
summarizationTimeoutMs: 120_000,
summarizationTimeoutMs: 300_000,
}
export interface CompressedResult {
@@ -2332,10 +2332,11 @@ class WorkerProcess:
except OSError:
pass
def request(self, req: dict[str, Any]) -> dict[str, Any]:
def request(self, req: dict[str, Any], timeout: float | None = None) -> dict[str, Any]:
self.start()
self.last_used_at = time.time()
return _send_bridge_request(self.endpoint, req, self.REQUEST_TIMEOUT_SECONDS)
request_timeout = timeout if timeout is not None and timeout > 0 else self.REQUEST_TIMEOUT_SECONDS
return _send_bridge_request(self.endpoint, req, request_timeout)
def _worker_endpoint(key: str) -> str:
@@ -2648,10 +2649,19 @@ class BridgeBroker:
forwarded = dict(req)
forwarded["profile"] = profile
forwarded.pop("worker_key", None)
resp = worker.request(forwarded)
resp = worker.request(forwarded, self._worker_request_timeout(req))
self._record_response_routes(profile, key, resp)
return resp
def _worker_request_timeout(self, req: dict[str, Any]) -> float:
try:
timeout = float(req.get("timeout", 0) or 0)
except (TypeError, ValueError):
timeout = 0
if timeout <= 0:
return WorkerProcess.REQUEST_TIMEOUT_SECONDS
return max(WorkerProcess.REQUEST_TIMEOUT_SECONDS, timeout + 10)
def handle(self, req: dict[str, Any]) -> dict[str, Any]:
action = str(req.get("action") or "").strip()
if not action:
@@ -250,6 +250,7 @@ export class ChatRunSocket {
socket.on('clarify.respond', async (data: { session_id?: string; clarify_id?: string; response?: string }) => {
if (!data.session_id || !data.clarify_id) return
this.clearClarifyEventState(data.session_id, data.clarify_id)
try {
const result = await this.bridge.clarifyRespond(data.clarify_id, data.response || '')
this.emitToSession(socket, data.session_id, 'clarify.resolved', {
@@ -386,6 +387,19 @@ export class ChatRunSocket {
// --- Helpers ---
private clearClarifyEventState(sessionId: string, clarifyId: string) {
const state = this.sessionMap.get(sessionId)
if (!state?.events.length) return
const nextEvents = state.events.filter(({ event, data }) => {
if (event !== 'clarify.requested' && event !== 'clarify.resolved') return true
return data?.clarify_id !== clarifyId
})
if (nextEvents.length !== state.events.length) {
state.events = nextEvents
}
}
private emitToSession(socket: Socket, sessionId: string, event: string, payload: any) {
const tagged = { ...payload, session_id: sessionId }
this.nsp.to(`session:${sessionId}`).emit(event, tagged)