fix: resolve race condition and add cleanup in HITL flow

This commit is contained in:
CREDO23 2026-02-13 19:17:36 +02:00
parent 743b40ece6
commit 2a15e0d337
2 changed files with 37 additions and 16 deletions

View file

@ -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) {

View file

@ -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>