Skip to content

Commit 1ee9997

Browse files
fix(rest-api): complete review hardening
Co-authored-by: jidechao <62241490+jidechao@users.noreply.github.com>
1 parent 59d7373 commit 1ee9997

9 files changed

Lines changed: 982 additions & 851 deletions

File tree

frontend/src/hooks/useSSEStream.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ export function useSSEStream() {
5757
onEvent("error", { message: err?.message || t("requestFailed") });
5858
}
5959
} finally {
60-
ctrlRef.current = null;
61-
setBusy(false);
60+
// A replaced stream may finish after its successor has started. Only
61+
// clear state when this controller still owns the active stream.
62+
if (ctrlRef.current === ctrl) {
63+
ctrlRef.current = null;
64+
setBusy(false);
65+
}
6266
}
6367
}, [t]);
6468

frontend/src/views/Chat.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ export default function Chat({ kb }) {
3636
useEffect(() => { if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight; }, [msgs]);
3737

3838
function newSession() {
39+
stop();
3940
setSessionId(null);
4041
setMsgs([]);
4142
}
4243

4344
async function loadHistory(sid) {
45+
stop();
4446
setSessionId(sid);
4547
setMsgs([]);
4648
try {

openkb/agent/chat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
build_query_agent,
3131
iter_agent_response_events,
3232
)
33+
from openkb.config import LlmCredentialBundle
3334
from openkb.log import append_log
3435

3536
_STYLE_DICT: dict[str, str] = {

0 commit comments

Comments
 (0)