Skip to content

Log DEMO_MODE state at startup#6

Closed
Ho1yShif wants to merge 1 commit into
mainfrom
fix/demo-mode-startup-logging
Closed

Log DEMO_MODE state at startup#6
Ho1yShif wants to merge 1 commit into
mainfrom
fix/demo-mode-startup-logging

Conversation

@Ho1yShif

Copy link
Copy Markdown
Collaborator

Why

The demo's per-visitor isolation + ephemeral history (PRs #4, #5) is gated on DEMO_MODE being a parse-truthy value in the process environment: 1|true|yes|on, case-insensitive, whitespace-trimmed — quotes are NOT stripped (deeptutor/services/demo/rate_limiter.py:71).

We hit a case where the Render dashboard had DEMO_MODE=true set, the service was redeployed, yet demo history was still shared across visitors and survived redeploys. Root cause was configuration, not code — the process was still seeing demo mode as off — but there was no log line to reveal that, so it looked like the isolation code was broken.

Verified empirically that a quoted value silently fails:

DEMO_MODE=true    -> is_demo_mode() == True
DEMO_MODE unset   -> is_demo_mode() == False
DEMO_MODE='"true"' -> is_demo_mode() == False   # quotes not stripped

What

Add one startup log line in the lifespan handler that prints the raw os.environ["DEMO_MODE"] value and the resolved demo state:

DEMO_MODE raw='true' -> demo mode ENABLED; per-visitor ephemeral history ACTIVE
DEMO_MODE raw=None   -> demo mode disabled; per-visitor ephemeral history OFF (single shared on-disk store)

A dashboard says true vs process sees off mismatch is now visible at a glance in deploy logs.

Scope / safety

  • Diagnostics only — no behaviour change.
  • Wrapped in try/except so it can never block startup.
  • Does not enable demo mode anywhere and does not touch render.yaml (the template intentionally ships DEMO_MODE off so private forks are unaffected).

Verification

  • pre-commit run --files deeptutor/api/main.py → ruff, ruff-format, mypy, bandit, detect-secrets all pass.
  • Smoke-tested is_demo_mode() for set / unset / quoted values (see table above).

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
@Ho1yShif Ho1yShif closed this Jul 14, 2026
@Ho1yShif Ho1yShif deleted the fix/demo-mode-startup-logging branch July 14, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant