Files
Jyotisha/scripts/diagnose_vedastro_mode.py
ClaudeandClaude 4b8a645357
Independent Staging Quality Gate / validate-python (push) Successful in 5m2s
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m44s
Independent Staging Quality Gate / publish (push) Successful in 12m12s
fix(vedastro): one switch, off by default; an official chart replaces the local one only on a matching echo (BUG-2427, #327)
Owner decision 2026-11-26: the product stops using VedAstro.
- scripts/vedastro_switch: VEDASTRO_ENABLED=1 turns it on; default off.
- Adapter, gateway, foreground session, consult gate, orchestrator,
  user entrypoint, REST/MCP/SDK bridges answer "disabled" at once:
  no network, no subprocess, no wait, no cache writes.
- vedastro_priority: a disabled snapshot leaves the local chart as is;
  an official chart replaces it only when every chart/house answer
  echoes the requested time, place and ayanamsa.
- Model input drops VedAstro audit rows, cross-check and must-use layer;
  privacy policy drops the VedAstro data line.
- VEDASTRO_API_KEY optional and unused; env examples, deploy/README,
  AGENTS.md updated. Frozen files untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-26 23:33:41 +08:00

156 lines
6.8 KiB
Python

#!/usr/bin/env python3
"""Report whether the current runtime is fast fallback or VedAstro official mode."""
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
try:
from scripts.local_env import load_local_env
except ModuleNotFoundError: # pragma: no cover - direct script execution
from local_env import load_local_env
ROOT = Path(__file__).resolve().parents[1]
FAST_TIMEOUT_THRESHOLD_SECONDS = 5.0
_DEPRECATED_FREE_TIER_QUEUE_ENVS = (
"VEDASTRO_FREE_TIER_QUEUE",
"VEDASTRO_FREE_TIER_QUEUE_ENABLED",
"VEDASTRO_ENABLE_FREE_TIER_QUEUE",
)
def _deprecated_free_tier_queue_env() -> list[str]:
"""Env names that used to be reported as the queue switch. They do not control it."""
return [name for name in _DEPRECATED_FREE_TIER_QUEUE_ENVS if os.environ.get(name, "").strip()]
def _free_tier_queue_enabled() -> bool:
try:
from scripts.vedastro_service_adapter import free_tier_throttle_state
except ModuleNotFoundError:
from vedastro_service_adapter import free_tier_throttle_state
return bool(free_tier_throttle_state()["active"])
def _timeout_seconds() -> float:
raw = os.environ.get("VEDASTRO_TIMEOUT_SECONDS", "").strip()
if not raw:
return 20.0
try:
return float(raw)
except ValueError:
return 4.0
def build_report() -> dict:
load_local_env(ROOT)
endpoint = os.environ.get("VEDASTRO_API_ENDPOINT", "https://api.vedastro.org/api").strip()
network_enabled = os.environ.get("VEDASTRO_ENABLE_NETWORK", "1").strip().lower() in {"1", "true", "yes", "on"}
timeout_seconds = _timeout_seconds()
has_api_key = bool(os.environ.get("VEDASTRO_API_KEY", "").strip())
free_tier_queue_enabled = _free_tier_queue_enabled()
deprecated_env_present = _deprecated_free_tier_queue_env()
missing = []
readiness_blockers = []
try:
from scripts.vedastro_switch import DISABLED_REASON, ENABLED_ENV, vedastro_enabled
except ModuleNotFoundError: # pragma: no cover - direct script execution
from vedastro_switch import DISABLED_REASON, ENABLED_ENV, vedastro_enabled
enabled = vedastro_enabled()
if not enabled:
# BUG-2427: off by owner decision; that is the intended state, not a readiness gap.
missing.append(f"{ENABLED_ENV}=1")
readiness_blockers.append(DISABLED_REASON)
elif not endpoint:
missing.append("VEDASTRO_API_ENDPOINT")
readiness_blockers.append("missing_endpoint")
if enabled and not network_enabled:
missing.append("VEDASTRO_ENABLE_NETWORK=1")
readiness_blockers.append("network_disabled")
if enabled and timeout_seconds <= FAST_TIMEOUT_THRESHOLD_SECONDS:
missing.append("VEDASTRO_TIMEOUT_SECONDS>5")
readiness_blockers.append("timeout_too_low")
if enabled and endpoint and network_enabled and not has_api_key:
readiness_blockers.append("premium_key_missing")
official_ready = not missing
mode = "official_extended" if official_ready else ("disabled" if not enabled else "fast_local_fallback")
return {
"enabled": enabled,
"mode": mode,
"official_ready": official_ready,
"endpoint_configured": bool(endpoint),
"network_enabled": network_enabled,
"timeout_seconds": timeout_seconds,
"has_api_key": has_api_key,
"free_tier_queue_enabled": free_tier_queue_enabled,
"deprecated_env_present": deprecated_env_present,
"free_tier_possible_with_cache_queue": bool(enabled and endpoint and network_enabled and timeout_seconds > FAST_TIMEOUT_THRESHOLD_SECONDS),
"missing": missing,
"readiness_blockers": readiness_blockers,
"expected_fallback_status": (
"none_if_official_endpoint_responds"
if official_ready
else "official_snapshot_budget_exhausted_or_endpoint_blocked"
),
"official_transport": "rest",
"official_calculate_endpoint": "https://api.vedastro.org/api/Calculate",
"rate_limit_per_minute": 5,
"mcp_bridge_role": "protocol_probe_only",
"official_closure_plan": {
"required_env": {
"VEDASTRO_API_ENDPOINT": endpoint or "https://api.vedastro.org/api",
"VEDASTRO_ENABLE_NETWORK": "1",
"VEDASTRO_TIMEOUT_SECONDS": "20",
"VEDASTRO_ENABLED": "1 (off by owner decision 2026-11-26; research only)",
"VEDASTRO_API_KEY": "optional; unused while VEDASTRO_ENABLED is off",
},
"free_tier_policy": "Official REST Calculate is limited to 5 requests/minute. Queue/cache can reduce throttling, but free tier may still return blocked or partial snapshots.",
"premium_key_policy": "API key recommended for stable official full snapshot; free tier may still block or throttle.",
"raw_response_acceptance": "vedastro_official.raw_response must be present before claiming official cloud closure.",
"default_path": "REST bridge scripts/vedastro_rest_bridge.py against /api/Calculate. Official MCP tools/call is protocol-probe only.",
},
"next_step": (
"Run full-reading or strict_workflow; verify vedastro_official.status is ok/partial."
if official_ready
else "Copy .env.official.example to .env.local and fill endpoint/network settings for official mode."
),
}
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--json", action="store_true", help="print machine-readable JSON")
args = parser.parse_args()
report = build_report()
if args.json:
print(json.dumps(report, ensure_ascii=False, sort_keys=True))
return 0
print(f"VedAstro runtime mode: {report['mode']}")
print(f"official_ready: {str(report['official_ready']).lower()}")
print(f"endpoint_configured: {str(report['endpoint_configured']).lower()}")
print(f"network_enabled: {str(report['network_enabled']).lower()}")
print(f"timeout_seconds: {report['timeout_seconds']}")
print(f"has_api_key: {str(report['has_api_key']).lower()}")
print(f"free_tier_possible_with_cache_queue: {str(report['free_tier_possible_with_cache_queue']).lower()}")
print(f"free_tier_queue_enabled: {str(report['free_tier_queue_enabled']).lower()}")
print(f"deprecated_env_present: {', '.join(report['deprecated_env_present']) or 'none'}")
if report["readiness_blockers"]:
print(f"readiness_blockers: {', '.join(report['readiness_blockers'])}")
if report["missing"]:
print("missing:")
for item in report["missing"]:
print(f" - {item}")
print(f"expected_fallback_status: {report['expected_fallback_status']}")
print(f"next_step: {report['next_step']}")
return 0
if __name__ == "__main__":
raise SystemExit(main())