fix: keep foreground consultations responsive

This commit is contained in:
Jesse_Chen
2026-08-11 11:59:14 +08:00
parent 8eed0603f9
commit 620131d6a8
9 changed files with 191 additions and 36 deletions
+52 -32
View File
@@ -839,6 +839,7 @@ def execute_consultation_workflow(
question = body.get('question') or ''
entry_mode = body.get('entry_mode', 'direct_chart')
high_rigor = bool(body.get('return_high_rigor_shape'))
defer_optional_external_evidence = bool(body.get('defer_optional_external_evidence'))
try:
from scripts.three_engine_parity_replay_validator import validate_manifest
except ModuleNotFoundError: # pragma: no cover - direct script execution
@@ -949,7 +950,10 @@ def execute_consultation_workflow(
executed_steps.append('run_rectification_gate')
elif step == 'compute_chart':
if not computed_chart:
chart = handler._compute_chart(birth_payload)
chart = handler._compute_chart({
**birth_payload,
'skip_vedastro_main_entry_overview': defer_optional_external_evidence,
})
computed_chart = True
executed_steps.append('compute_chart')
@@ -992,7 +996,14 @@ def execute_consultation_workflow(
executed_steps.append('run_thematic_report')
vedastro_gateway = rectification.get('vedastro_gateway') if isinstance(rectification, dict) else None
if not isinstance(vedastro_gateway, dict):
if defer_optional_external_evidence:
vedastro_gateway = {
'scope': 'vedastro_gateway_run',
'status': 'local_fallback',
'official_closure_state': 'official_blocked',
'official_closure_reason': 'foreground_optional_evidence_deferred',
}
elif not isinstance(vedastro_gateway, dict):
try:
vedastro_gateway = handler._compute_vedastro_gateway_run(body)
except Exception as exc: # Gateway evidence must not block the local chart result.
@@ -1232,6 +1243,7 @@ def _build_api_chart_cache_payload(body: dict) -> dict:
'node_mode': body.get('node_mode', body.get('nodeMode', 'mean')),
'today': body.get('today') or body.get('current_date'),
'transit_date': body.get('transit_date'),
'skip_vedastro_main_entry_overview': bool(body.get('skip_vedastro_main_entry_overview')),
},
'vedastro_runtime': _vedastro_runtime_fingerprint(),
}
@@ -5457,29 +5469,36 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
'dasha': result['dasha'],
'shadbala': {'planets': sb.get('planets', {})} if 'sb' in locals() and isinstance(sb, dict) else {},
}
_attach_vedastro_main_entry_overview(result, {
'year': year,
'month': month,
'day': day,
'hour': int(hour),
'minute': int(minute),
'second': int(second),
'lat': lat,
'lon': lon,
'tz': tz,
'ayanamsa': ayanamsa_name,
'node_mode': body.get('node_mode', body.get('nodeMode', 'mean')),
'today': body.get('today') or body.get('current_date'),
'transit_date': body.get('transit_date'),
})
if not body.get('skip_vedastro_main_entry_overview'):
_attach_vedastro_main_entry_overview(result, {
'year': year,
'month': month,
'day': day,
'hour': int(hour),
'minute': int(minute),
'second': int(second),
'lat': lat,
'lon': lon,
'tz': tz,
'ayanamsa': ayanamsa_name,
'node_mode': body.get('node_mode', body.get('nodeMode', 'mean')),
'today': body.get('today') or body.get('current_date'),
'transit_date': body.get('transit_date'),
})
_attach_guided_topics(result)
result['ai_prompt_pack'] = self._build_chart_prompt_pack(result)
return _store_api_chart_response_cache(cache_payload, result)
except ImportError:
fallback = self._fallback_chart(year, month, day, hour, minute, second, lat, lon, tz)
fallback = self._fallback_chart(
year, month, day, hour, minute, second, lat, lon, tz,
skip_vedastro_main_entry_overview=bool(body.get('skip_vedastro_main_entry_overview')),
)
return _store_api_chart_response_cache(cache_payload, fallback)
def _fallback_chart(self, year, month, day, hour, minute, second, lat, lon, tz):
def _fallback_chart(
self, year, month, day, hour, minute, second, lat, lon, tz,
*, skip_vedastro_main_entry_overview=False,
):
"""无Swiss Ephemeris时的简化计算"""
import hashlib
seed = int(hashlib.md5(f"{year}{month}{day}{hour}{minute}{second}{lat}{lon}".encode()).hexdigest()[:8], 16)
@@ -5544,19 +5563,20 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
'dasha': result['dasha'],
'shadbala': {},
}
_attach_vedastro_main_entry_overview(result, {
'year': year,
'month': month,
'day': day,
'hour': int(hour),
'minute': int(minute),
'second': int(second),
'lat': lat,
'lon': lon,
'tz': tz,
'ayanamsa': 'lahiri',
'node_mode': 'mean',
})
if not skip_vedastro_main_entry_overview:
_attach_vedastro_main_entry_overview(result, {
'year': year,
'month': month,
'day': day,
'hour': int(hour),
'minute': int(minute),
'second': int(second),
'lat': lat,
'lon': lon,
'tz': tz,
'ayanamsa': 'lahiri',
'node_mode': 'mean',
})
_attach_guided_topics(result)
result['ai_prompt_pack'] = self._build_chart_prompt_pack(result)
return result