Skip to content

Commit 48b2f0a

Browse files
meizhong986claude
andcommitted
fix: prevent repeated 'Process Completed' messages after LLM translation
Root cause: setInterval with async callbacks does not prevent overlapping execution. pywebview's message queue backs up during heavy LLM token streaming (dense stdout from local LLM). When the process exits and load drops, all backed-up get_process_status() calls resolve simultaneously — each sees status='completed' and each calls ErrorHandler.showSuccess, printing the success message many times. Fix: add a guard immediately after each `await pywebview.api.*` call that checks `AppState.statusPollInterval` (or logPollInterval). The first callback to handle completion calls stopStatusMonitoring() which sets the ref to null. All subsequent in-flight callbacks see null and return early, executing the completion handler exactly once. Applied to both startStatusMonitoring (500ms) and startLogPolling (100ms). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 541ba29 commit 48b2f0a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • whisperjav/webview_gui/assets

whisperjav/webview_gui/assets/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,9 @@ const ProcessManager = {
949949
try {
950950
const logs = await pywebview.api.get_logs();
951951

952+
// Guard against overlapping async callbacks (same race as status monitor)
953+
if (!AppState.logPollInterval) return;
954+
952955
if (logs && logs.length > 0) {
953956
logs.forEach(line => {
954957
// Remove trailing newline if present
@@ -978,6 +981,14 @@ const ProcessManager = {
978981
try {
979982
const status = await pywebview.api.get_process_status();
980983

984+
// Guard: another concurrent callback may have already handled completion
985+
// and called stopStatusMonitoring() while this one was awaiting.
986+
// setInterval with async callbacks does not prevent overlap — multiple
987+
// in-flight callbacks can all see status='completed' when the pywebview
988+
// message queue drains after heavy LLM streaming. Only the first one
989+
// should act; the rest must exit here.
990+
if (!AppState.statusPollInterval) return;
991+
981992
// Update status label
982993
ProgressManager.setStatus(this.formatStatus(status.status));
983994

0 commit comments

Comments
 (0)