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]);
// Cleanup on unmount - abort any in-flight requests
useEffect(() => {
return () => {
if (abortControllerRef.current) {
abortControllerRef.current.abort();
abortControllerRef.current = null;
}
};
}, []);
// Cancel ongoing request
const cancelRun = useCallback(async () => {
if (abortControllerRef.current) {
@ -952,25 +962,36 @@ export default function NewChatPage() {
contentPartsState.currentTextPartIndex = -1;
}
}
}
}
}
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,
};
}
// 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;
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 {
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";

View file

@ -341,7 +341,7 @@ function SuccessCard({ result }: { result: SuccessResult }) {
</p>
</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">
{result.title && (
<div>