fix(dsh): retain stop intent and decode split UTF-8 output

This commit is contained in:
阿白叔 committed 2026-10-31 14:49:55 +08:00
1 parent 6f9f820f85
commit 0bc1f64edc
7 files changed
+265 -9

No files matched your search

@@ -47,13 +47,13 @@ class DshAutomation(QObject):
except (OSError, ValueError, KeyError):
continue
def enqueue(self, task_id, issue_code, message, *, execution_authorized=False, run_id='observation'):
def enqueue(self, task_id, issue_code, message, *, execution_authorized=False, run_id='observation', stop_event=None):
# Offscreen UI unit tests have no Chromium surface or local provider.
if QApplication.platformName().casefold() == 'offscreen':
return False
if issue_code == 'operation_cancelled' or not task_id:
return False
item = (task_id, issue_code, message, execution_authorized, run_id)
item = (task_id, issue_code, message, execution_authorized, run_id, stop_event)
identity = (task_id, issue_code, run_id)
if identity in self.seen:
return True
@@ -69,7 +69,7 @@ class DshAutomation(QObject):
if w._workers or w._loading:
QTimer.singleShot(200, self._drain)
return
task_id, code, message, authorized, run_id = self.pending.pop(0)
task_id, code, message, authorized, run_id, original_stop = self.pending.pop(0)
self.latest = {}
self._native_unavailable = False
try:
@@ -82,7 +82,9 @@ class DshAutomation(QObject):
view.diagnosis_event.connect(self._diagnosis_event)
view.stopped.connect(self._runtime_stopped)
self._connected_view = view
stop = StopControl()
# Carry the original run's stop/force intent through the asynchronous
# handoff, including pauses requested after enqueue but before drain.
stop = original_stop if original_stop is not None else StopControl()
# The same worker gate reserves the mutation lane throughout diagnosis.
w._batch_stop = stop
w._active_quick_run_task_id = task_id
@@ -2,6 +2,7 @@
from __future__ import annotations
import json
import codecs
from pathlib import Path
from PySide6.QtCore import QProcess, QProcessEnvironment, QTimer, QUrl, Signal
@@ -43,7 +44,7 @@ class NativeHarnessView(QWidget):
self._diagnosis_queue = []
self._pending_context = None
self._context_attempts = 0
self._buffer = ''
self._reset_output()
self._started = False
self._stopping = False
self.last_error = ''
@@ -116,6 +117,7 @@ class NativeHarnessView(QWidget):
def start(self):
if self.is_running:
return
self._reset_output()
if self.context is None and self._pending_context is None:
self.bind(TaskSnapshot('', 'observe'))
root = integration_root()
@@ -124,7 +126,6 @@ class NativeHarnessView(QWidget):
return
self._stopping = False
self._started = False
self._buffer = ''
self.status.setText('正在加载 DeepSeek Harness 官方界面…')
self.status.show()
self.retry.hide()
@@ -143,8 +144,13 @@ class NativeHarnessView(QWidget):
self.process.start()
self.timeout.start(60000)
def _reset_output(self):
self._buffer = ''
self._stdout_decoder = codecs.getincrementaldecoder('utf8')('replace')
self._stderr_decoder = codecs.getincrementaldecoder('utf8')('replace')
def _stdout(self):
self._buffer += bytes(self.process.readAllStandardOutput()).decode('utf8', 'replace')
self._buffer += self._stdout_decoder.decode(bytes(self.process.readAllStandardOutput()))
lines = self._buffer.split('\n')
self._buffer = lines.pop()
for line in lines:
@@ -175,7 +181,7 @@ class NativeHarnessView(QWidget):
self.action_requested.emit(request)
def _stderr(self):
self.last_error = (self.last_error + bytes(self.process.readAllStandardError()).decode('utf8', 'replace'))[-12000:]
self.last_error = (self.last_error + self._stderr_decoder.decode(bytes(self.process.readAllStandardError())))[-12000:]
def _failed(self, text):
if self._stopping or not isValid(self.status):
@@ -43,6 +43,7 @@ class TrialTaskCenterWindow(MaterialMainWindow):
self._dsh_stopping = False
self._dsh_automation = None
self._dsh_run_id = 'observation'
self._dsh_run_stop = None
self._dsh_authorized_tasks = set()
self.task_center_action = QAction('任务中心', self)
self.task_center_action.triggered.connect(lambda: self.content_stack.setCurrentIndex(0))
@@ -700,6 +701,7 @@ class TrialTaskCenterWindow(MaterialMainWindow):
from uuid import uuid4
self._dsh_run_id = uuid4().hex
self._batch_stop = StopControl()
self._dsh_run_stop = self._batch_stop
self._active_quick_run_task_id = task_id
self._run_started_at = time.time()
self._quick_run_elapsed.start()
@@ -708,6 +710,11 @@ class TrialTaskCenterWindow(MaterialMainWindow):
self._message = ''
def _finish_run(self):
# Completion may report paused=False after the final failed item.
# Keep the original stop/force object for incidents from this run;
# only a newly authorized _begin_run replaces it with a fresh control.
if self._batch_stop is not None:
self._dsh_run_stop = self._batch_stop
self._quick_run_timer.stop()
self._feedback_query.invalidate()
self._active_quick_run_task_id = None
@@ -1117,4 +1124,5 @@ class TrialTaskCenterWindow(MaterialMainWindow):
from .dsh_automation import DshAutomation
self._dsh_automation = DshAutomation(self)
return self._dsh_automation.enqueue(task_id, issue_code, message,
execution_authorized=task_id in self._dsh_authorized_tasks, run_id=self._dsh_run_id)
execution_authorized=task_id in self._dsh_authorized_tasks, run_id=self._dsh_run_id,
stop_event=self._batch_stop if self._batch_stop is not None else self._dsh_run_stop)