mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
fix: resolve race condition and add cleanup in HITL flow
This commit is contained in:
parent
743b40ece6
commit
2a15e0d337
2 changed files with 37 additions and 16 deletions
|
|
@ -390,6 +390,16 @@ export default function NewChatPage() {
|
||||||
}));
|
}));
|
||||||
}, [currentThread, setCurrentThreadState]);
|
}, [currentThread, setCurrentThreadState]);
|
||||||
|
|
||||||
|
// Cleanup on unmount - abort any in-flight requests
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Cancel ongoing request
|
// Cancel ongoing request
|
||||||
const cancelRun = useCallback(async () => {
|
const cancelRun = useCallback(async () => {
|
||||||
if (abortControllerRef.current) {
|
if (abortControllerRef.current) {
|
||||||
|
|
@ -955,6 +965,17 @@ export default function NewChatPage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge edited args if present to fix race condition
|
||||||
|
if (decisions.length > 0 && decisions[0].type === "edit" && decisions[0].edited_action) {
|
||||||
|
const editedAction = decisions[0].edited_action;
|
||||||
|
for (const part of contentParts) {
|
||||||
|
if (part.type === "tool-call" && part.toolName === editedAction.name) {
|
||||||
|
part.args = { ...part.args, ...editedAction.args };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const decisionType = decisions[0]?.type as "approve" | "reject" | undefined;
|
const decisionType = decisions[0]?.type as "approve" | "reject" | undefined;
|
||||||
if (decisionType) {
|
if (decisionType) {
|
||||||
for (const part of contentParts) {
|
for (const part of contentParts) {
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ function SuccessCard({ result }: { result: SuccessResult }) {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{result.deleted_from_db || result.title && (
|
{(result.deleted_from_db || result.title) && (
|
||||||
<div className="space-y-2 px-4 py-3 text-xs">
|
<div className="space-y-2 px-4 py-3 text-xs">
|
||||||
{result.title && (
|
{result.title && (
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue