From fa4bea40220257f93a902dd68f007c752e1ae7a2 Mon Sep 17 00:00:00 2001 From: Ho1yShif Date: Tue, 14 Jul 2026 10:36:53 -0700 Subject: [PATCH] Log DEMO_MODE state at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The demo's per-visitor isolation and ephemeral-history behaviour is gated on DEMO_MODE being a parse-truthy value (1|true|yes|on, case-insensitive, whitespace-trimmed — quotes are NOT stripped) in the process environment. When the flag is mis-set (wrong key, a quoted value like "true", or set on an env scope not attached to the service) all of that silently no-ops, and until now nothing in the logs said so — making it look like the isolation code was broken when the real issue was configuration. Log the raw os.environ["DEMO_MODE"] value and the resolved demo state once at startup so a mismatch between "the dashboard says DEMO_MODE=true" and "the process sees demo mode off" is immediately visible in the deploy logs. Diagnostics only; wrapped so it can never block startup. No behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) --- deeptutor/api/main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/deeptutor/api/main.py b/deeptutor/api/main.py index cf4a764d..9865aa70 100644 --- a/deeptutor/api/main.py +++ b/deeptutor/api/main.py @@ -123,6 +123,27 @@ async def lifespan(app: FastAPI): # Execute on startup logger.info("Application startup") + # Demo-mode diagnostics. The per-visitor / ephemeral-history behaviour is + # gated on DEMO_MODE being a parse-truthy value in the *process* env + # (1|true|yes|on, case-insensitive, whitespace-trimmed — quotes are NOT + # stripped). Historically a mis-set flag (wrong key, quoted value, or wrong + # env scope) made all of that silently no-op with nothing in the logs to say + # so. Log the raw value and the resolved state so the mismatch is visible. + try: + import os + + from deeptutor.services.demo import is_demo_mode + + _demo_on = is_demo_mode() + logger.info( + "DEMO_MODE raw=%r -> demo mode %s; per-visitor ephemeral history %s", + os.environ.get("DEMO_MODE"), + "ENABLED" if _demo_on else "disabled", + "ACTIVE" if _demo_on else "OFF (single shared on-disk store)", + ) + except Exception as e: # pragma: no cover - diagnostics must never block startup + logger.warning(f"Failed to log demo-mode state at startup: {e}") + # Validate configuration consistency validate_tool_consistency()