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) {
|
||||||
|
|
@ -952,25 +962,36 @@ export default function NewChatPage() {
|
||||||
contentPartsState.currentTextPartIndex = -1;
|
contentPartsState.currentTextPartIndex = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const decisionType = decisions[0]?.type as "approve" | "reject" | undefined;
|
// Merge edited args if present to fix race condition
|
||||||
if (decisionType) {
|
if (decisions.length > 0 && decisions[0].type === "edit" && decisions[0].edited_action) {
|
||||||
for (const part of contentParts) {
|
const editedAction = decisions[0].edited_action;
|
||||||
if (
|
for (const part of contentParts) {
|
||||||
part.type === "tool-call" &&
|
if (part.type === "tool-call" && part.toolName === editedAction.name) {
|
||||||
typeof part.result === "object" &&
|
part.args = { ...part.args, ...editedAction.args };
|
||||||
part.result !== null &&
|
break;
|
||||||
"__interrupt__" in (part.result as Record<string, unknown>)
|
|
||||||
) {
|
|
||||||
part.result = {
|
|
||||||
...(part.result as Record<string, unknown>),
|
|
||||||
__decided__: decisionType,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const decisionType = decisions[0]?.type as "approve" | "reject" | undefined;
|
||||||
|
if (decisionType) {
|
||||||
|
for (const part of contentParts) {
|
||||||
|
if (
|
||||||
|
part.type === "tool-call" &&
|
||||||
|
typeof part.result === "object" &&
|
||||||
|
part.result !== null &&
|
||||||
|
"__interrupt__" in (part.result as Record<string, unknown>)
|
||||||
|
) {
|
||||||
|
part.result = {
|
||||||
|
...(part.result as Record<string, unknown>),
|
||||||
|
__decided__: decisionType,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
||||||
|
|
|
||||||
|
|
@ -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