R3.2.8.6-R1 Reasoning-Only Exhaustion Recovery

#27
Files changed (1) hide show
  1. core/pipeline_agent.py +47 -7
core/pipeline_agent.py CHANGED
@@ -44,6 +44,10 @@ class DeepSeekRequestError(DeepSeekAPIError):
44
  pass
45
 
46
 
 
 
 
 
47
  class PipelineCancelledError(RuntimeError):
48
  """Raised when the Worker or local task state requests cancellation."""
49
 
@@ -869,6 +873,7 @@ class SSciPipelineAgent:
869
  reasoning_effort=None,
870
  temp=0.3,
871
  allow_fallback=None,
 
872
  ):
873
  (
874
  requested_model,
@@ -1032,6 +1037,11 @@ class SSciPipelineAgent:
1032
  yield "\n</think>\n"
1033
 
1034
  if not emitted_content:
 
 
 
 
 
1035
  raise DeepSeekAPIError(
1036
  "DeepSeek stream ended without final content."
1037
  )
@@ -1048,6 +1058,9 @@ class SSciPipelineAgent:
1048
 
1049
  except GeneratorExit:
1050
  raise
 
 
 
1051
  except (
1052
  DeepSeekAuthenticationError,
1053
  DeepSeekBalanceError,
@@ -1192,13 +1205,40 @@ class SSciPipelineAgent:
1192
  user_prompt = APP_CONFIG["prompt_templates"]["synthesis_user"].replace(
1193
  "{topic}", topic).replace("{user_injection}", user_injection).replace(
1194
  "{refs_text}", refs_text).replace("{directive}", APP_CONFIG['deep_synthesis_directive'])
1195
- return self.stream_deepseek(
1196
- sys_prompt,
1197
- user_prompt,
1198
- model_role="reasoning",
1199
- thinking=True,
1200
- allow_fallback=False,
1201
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1202
 
1203
  # Generate abstract and conclusion anchors from literature plus evidence.
1204
  def stream_generate_research_logic(
 
44
  pass
45
 
46
 
47
+ class DeepSeekReasoningOnlyExhaustionError(DeepSeekAPIError):
48
+ """Reasoning tokens were emitted but no final answer content arrived."""
49
+
50
+
51
  class PipelineCancelledError(RuntimeError):
52
  """Raised when the Worker or local task state requests cancellation."""
53
 
 
873
  reasoning_effort=None,
874
  temp=0.3,
875
  allow_fallback=None,
876
+ reasoning_only_recovery=False,
877
  ):
878
  (
879
  requested_model,
 
1037
  yield "\n</think>\n"
1038
 
1039
  if not emitted_content:
1040
+ if reasoning_only_recovery and reasoning_chunks > 0:
1041
+ raise DeepSeekReasoningOnlyExhaustionError(
1042
+ "DeepSeek reasoning-only exhaustion: "
1043
+ f"reasoning_chunks={reasoning_chunks}; final content absent."
1044
+ )
1045
  raise DeepSeekAPIError(
1046
  "DeepSeek stream ended without final content."
1047
  )
 
1058
 
1059
  except GeneratorExit:
1060
  raise
1061
+ except DeepSeekReasoningOnlyExhaustionError:
1062
+ self._touch_execution_progress("deepseek_reasoning_only_exhaustion")
1063
+ raise
1064
  except (
1065
  DeepSeekAuthenticationError,
1066
  DeepSeekBalanceError,
 
1205
  user_prompt = APP_CONFIG["prompt_templates"]["synthesis_user"].replace(
1206
  "{topic}", topic).replace("{user_injection}", user_injection).replace(
1207
  "{refs_text}", refs_text).replace("{directive}", APP_CONFIG['deep_synthesis_directive'])
1208
+
1209
+ def _stream_with_reasoning_exhaustion_recovery():
1210
+ try:
1211
+ yield from self.stream_deepseek(
1212
+ sys_prompt,
1213
+ user_prompt,
1214
+ model_role="reasoning",
1215
+ thinking=True,
1216
+ allow_fallback=False,
1217
+ reasoning_only_recovery=True,
1218
+ )
1219
+ return
1220
+ except DeepSeekReasoningOnlyExhaustionError as exc:
1221
+ logging.warning(
1222
+ "Literature synthesis reasoning-only exhaustion; retrying once with thinking disabled: %s",
1223
+ exc,
1224
+ )
1225
+ self._touch_execution_progress("literature_synthesis_direct_recovery")
1226
+
1227
+ recovery_system = (
1228
+ sys_prompt
1229
+ + "\n\nRECOVERY MODE: Produce the final literature synthesis directly. "
1230
+ "Do not perform extended hidden reasoning. Preserve the original evidence, "
1231
+ "citation boundaries, uncertainty, and scope; do not invent facts."
1232
+ )
1233
+ yield from self.stream_deepseek(
1234
+ recovery_system,
1235
+ user_prompt,
1236
+ model_role="reasoning",
1237
+ thinking=False,
1238
+ allow_fallback=False,
1239
+ )
1240
+
1241
+ return _stream_with_reasoning_exhaustion_recovery()
1242
 
1243
  # Generate abstract and conclusion anchors from literature plus evidence.
1244
  def stream_generate_research_logic(