Skip to content

Public Scenarios app on the installer stack - #57

Merged
benhayes21 merged 16 commits into
fix/workflow-bugsfrom
feature/scenarios-app
Nov 6, 2026
Merged

benhayes21 merged 16 commits into
fix/workflow-bugsfrom
feature/scenarios-app

Conversation

@benhayes21

@benhayes21 benhayes21 commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

A separate, credential-free Scenarios app for the public demo: newer users run pre-loaded disaster scenarios against pre-loaded exposure and explore the results, but cannot upload or delete anything. The hosted demo moves onto the installer stack, with only the UI exposed.

Scenario names: merge OasisLMF/Scenarios#6 for the short display names; until then the existing (longer) model settings names are shown.

Stacked on #55 — this PR targets fix/workflow-bugs so the diff shows only the Scenarios work. When #55 merges and its branch is deleted, GitHub will retarget this PR to main.

Closes the newcomer-explanation part of #30. PiWind is no longer one of the scenarios (13 scenarios).

Scenarios app (scenarios_app.py, pages in scenarios_ui/)

  • Run a scenario — find a scenario in a compact table with search and filters by peril, country and provider. All scenario information comes from the scenario data: names and descriptions from each model's settings (short display names in Short display names for the scenario models; add Ghana E760461 model settings Scenarios#6), peril and countries from the exposure (OED names), check its exposure (figures and map), choose samples and a loss breakdown (by location by default when the exposure has coordinates), run with live progress (current task, events x of y), and see results on the page with a zip download
  • Showcase — pre-computed runs for every scenario, so there's no waiting. Losses are broken down by location where the exposure has coordinates (heatmap) or by country where it spans several (country map); only runs of configured scenarios are listed, labelled with the scenario's current name
  • Compare — two runs side by side, from the showcase and the visitor's own runs (moved from pages/comparison.py)
  • Guide — rewritten for newcomers, including samples vs analytical mean

Visitors are identified by an id in the URL (?v=..., carried on every link and kept on reload); runs are tagged with it, so visitors only see their own runs plus the showcase. Limits (scenarios section of scenarios/ui-config.json): max samples (50), active runs per visitor (2) and site-wide (3), processes per run (2).

Locked down: st.navigation registers only the Scenarios pages, so the standard UI's pages (uploads, deletes) are not reachable from this app — requesting one falls back to the default page (tested).

Results (both apps)

  • Sample results by default with the analytical mean as the second option, in every output that has both (MELT, PLT, AAL, ALT, MPLT, comparisons)
  • Event filter on MELT, SELT and QELT when there is more than one event (largest loss first)
  • Maps frame the locations with a loss; the Map tab only appears when losses are grouped by location (with coordinates; 0,0 counts as not geocoded) or by country
  • The summary level selector resets when switching analyses (it kept the previous analysis's labels)

Public deployment on the installer stack

  • .env.scenarios template (OASIS_PUBLIC_DEMO=true, scenarios model set, simple auth, CHANGE_ME passwords)
  • docker-compose.public.yml: the UI runs the Scenarios app; only Traefik's 80/443 are published and only the UI is routed (no public API, websocket, database or broker ports — verified with docker compose config); a scenarios-prune service removes visitors' runs after OASIS_PRUNE_DAYS, keeping showcase runs
  • docker-compose.acme.yml (when OASIS_ACME_EMAIL is set): Let's Encrypt certificate for the public hostname
  • scenarios-setup one-shot: loads portfolios, settings templates and showcase runs; idempotent, runs every deploy
  • install.sh: --yes for unattended redeploys; refuses a public demo with non-simple auth or CHANGE_ME placeholders
  • scenarios/deploy_scenarios_ui.sh (run by the CD workflow) now uses install.sh
  • Removes oasis-scenarios-platform.yml, oasis-scenarios-ui.yml and deploy-scenarios.sh (published the API on :8000 with default admin credentials, :latest images), and the unused scenarios-ui-docker.yml workflow (built coreoasis/oasis_scenarios, which nothing uses: the deploy builds the image on the server)

Resource limits (from a local run that exhausted a 62 GB laptop)

Starting all 13 scenario showcase runs at once took the machine down: each worker ran one Celery process per CPU and each run used every core.

  • Runs cap kernel_num_processes / lookup_num_processes (processes_per_run, default 2)
  • Scenario workers: OASIS_WORKER_CONCURRENCY=1 and a container memory limit OASIS_WORKER_MEM_LIMIT=6g
  • Showcase runs are started one at a time; failed ones are replaced
  • Setup waits for all models to register before loading templates and showcase runs (it previously raced ahead once PiWind registered)

With these, all the scenarios' showcase runs completed sequentially on the laptop, with ≥39 GB free throughout. The hosted server is smaller (t3a.2xlarge: 32 GB, 8 vCPU, root disk 85% full), so these limits matter there too.

Platform READY gap (OasisLMF/OasisPlatform#1506)

generate_and_run reports READY between input generation and the loss run (record_input_files ignores analysis_finish_status). Workaround in both apps (modules/status.py): a READY analysis updated in the last two minutes counts as running — progress keeps refreshing, Run/Settings/Delete stay disabled, and it's labelled "Inputs ready, starting run". The showcase script waits for a final status.

Other changes

  • The UI and setup scripts take the service account from OASIS_SERVICE_USERNAME_OR_ID / OASIS_SERVICE_PASSWORD_OR_SECRET (set by install.sh from .env), falling back to secrets.toml, so credentials only live in .env
  • Results: outputs requested but not produced show a message instead of a stack trace (the views are fragments, which swallowed the previous try/except); .parquet outputs are found
  • Removes the old Scenarios pages, modules only they used, and the old guide screenshots

Test plan

  • pytest — 140 passed (Scenarios app: visitor isolation, run flow, limits, process caps, navigation lockdown, showcase/compare; READY-gap handling in both apps)
  • ruff and autopep8 clean
  • Visitor journey in a real browser (Playwright): choose → exposure → run → live progress → results; visitor id survives navigation and reload
  • Built image: app and setup run with env-var credentials only; no secrets in the image
  • Public compose config: only 80/443 published, only the UI routed
  • All 13 scenarios (data from the public Scenarios repo + S3) deployed locally with the installer; all 13 showcase runs completed, and each showcase's Map tab checked in the browser (11 maps: 10 by location, EUWS by country; MAEQ and TREQ have no coordinates and one country, so no Map tab)
  • Local rehearsal of the full public deploy (.env.scenarios with random passwords, ui.oasis.local): only 80/443 published; API, websocket, 51970, UI, database, broker, Redis and Traefik dashboard ports refused; /api never reaches the platform; app authenticates with the .env password (the secrets.toml one is rejected); 14 scenarios listed; standard UI URLs fall back to the Scenarios app; a run completed over HTTPS; showcase runs one at a time; prune deleted a visitor run and kept all showcase runs
  • Let's Encrypt and the remote deploy script on the hosted server (need public DNS / the server)

Fixed by the rehearsal: the installer's CHANGE_ME check matched a comment in .env.scenarios, so every public deploy was refused; and the prune script couldn't authenticate with oasislmf 2.5.9 (no auth type), so it never deleted anything. Prune now uses the shared login, which also keeps the password out of the process list.

Deploying to the hosted server (one-off)

The server already runs the installer stack, but on 2.5 images, an old branch, and ui.oasis.local/http behind a separate nginx proxy. Moving to this setup needs its .env created from .env.scenarios, and a decision on whether Traefik terminates TLS (Let's Encrypt) or the existing nginx stays in front. Existing visitor analyses won't carry over; the showcase is rebuilt automatically. Check disk space first.

🤖 Generated with Claude Code

benhayes21 and others added 16 commits November 5, 2026 17:17
The UI and setup scripts now take the service account from
OASIS_SERVICE_USERNAME_OR_ID / OASIS_SERVICE_PASSWORD_OR_SECRET (exported by
install.sh from .env), falling back to .streamlit/secrets.toml. A
deployment's credentials only need setting in .env, and secrets.toml can't
drift from the platform's admin password. quiet_login also handles failed
logins instead of crashing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The output views are Streamlit fragments, which display their own
exceptions, so the earlier try/except never caught a missing output and
users saw a stack trace. Results now check the file exists first.
OutputInterface also finds .parquet outputs (ORD parquet_format), which
were previously reported as missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A separate, credential-free app (scenarios_app.py, pages in scenarios_ui/)
for showing newcomers how to run models: visitors run pre-loaded scenarios
against pre-loaded exposure and explore the results, but cannot upload or
delete anything.

- st.navigation registers only the Scenarios pages, so the standard UI's
  pages are unreachable from this app (it ignores pages/)
- Run a scenario: choose a scenario (cards), check its exposure (figures and
  map), choose samples and a loss breakdown, run with live progress, and see
  results on the page; 'Your runs' lists the visitor's runs
- Showcase: pre-computed runs (tagged [showcase]) to explore without waiting
- Compare: two runs side by side, from the showcase and the visitor's own
  runs (moved from pages/comparison.py; skips outputs a run didn't produce)
- Guide: rewritten for newcomers, incl. samples vs analytical mean (#30)
- Visitors are identified by an id in the URL (?v=...), carried on every
  link; runs are tagged with it, so visitors only see their own runs
- Limits from the 'scenarios' config section: max samples, active runs per
  visitor and overall
- Reuses the standard UI's results, progress and exposure components

Removes the old Scenarios pages (pages/scenarios.py, scenariosGuide.py) and
modules only they used, and the old guide screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the hosted demo from the separate oasis-scenarios-*.yml stack to the
installer stack (2.5.9, Traefik, HTTPS):

- .env.scenarios: public demo template (OASIS_PUBLIC_DEMO=true, scenarios
  model set, simple auth, CHANGE_ME passwords)
- docker-compose.public.yml (added when OASIS_PUBLIC_DEMO=true): the UI runs
  the Scenarios app; only Traefik's http/https ports are published and only
  the UI is routed (no public API, websocket, database or broker ports);
  a scenarios-prune service removes visitors' runs older than
  OASIS_PRUNE_DAYS, keeping showcase runs
- docker-compose.acme.yml (added when OASIS_ACME_EMAIL is set): Let's
  Encrypt certificate for the public hostname
- scenarios-setup one-shot (scripts/scenarios_setup.sh): loads portfolios,
  settings templates and showcase runs; idempotent, runs on every deploy
- install.sh: --yes for unattended redeploys; refuses a public demo with
  non-simple auth or CHANGE_ME placeholders; public-aware summary
- scripts: add_showcase_analyses.py (new); prune_analysis.py --keep-tag;
  add_settings_template.py updates an existing template instead of adding
  duplicates; add_test_portfolios.py skips portfolios whose files are missing
- scenarios/deploy_scenarios_ui.sh (run by the CD workflow) now uses
  install.sh
- Removes oasis-scenarios-platform.yml, oasis-scenarios-ui.yml and
  deploy-scenarios.sh (published the API on :8000 with default admin
  credentials and used :latest images)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scenarios-setup waited for a single model, so on a fresh deploy it went
ahead as soon as PiWind registered and skipped the settings templates and
showcase runs of scenario workers still starting up. It now waits for all
14 workers' models (SCENARIOS_MIN_MODELS), and carries on with whatever
has registered if some never do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Starting every showcase run at once took down a 62GB laptop: each worker
ran one Celery process per CPU, and each run used every core for the
lookup and the loss calculation.

- Scenario and showcase runs cap their processes (kernel_num_processes /
  lookup_num_processes) at scenarios.processes_per_run (default 2)
- Scenario workers run one task at a time (OASIS_WORKER_CONCURRENCY,
  default 1) with a container memory limit (OASIS_WORKER_MEM_LIMIT,
  default 6g), so a run that outgrows it is killed in its container
- Showcase runs are started one at a time (--max-concurrent), waiting for
  each to finish; failed or cancelled showcase runs are replaced
- Site-wide concurrent visitor runs default to 3 (was 10)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A generate-and-run passes through READY between input generation and the
loss run. The showcase script took READY as finished and started the next
scenario alongside it, and the Scenarios app could stop refreshing a
visitor's progress and undercount active runs at that point.

- add_showcase_analyses.py waits for a final status (completed, error,
  cancelled)
- The Scenarios app counts a READY run updated in the last two minutes as
  still active (is_active), so a run stuck at READY doesn't block forever

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OasisPlatform's record_input_files always sets READY after input
generation, ignoring its analysis_finish_status argument (generate-and-run
passes RUN_STARTED). Until a worker picks up the loss run, the Analyses
page stopped refreshing progress and offered a Run button for an analysis
that was about to run anyway.

The READY-grace rule from the Scenarios app moves to modules/status.py
and is used by both apps: a READY analysis updated in the last two minutes
counts as running, keeps progress refreshing, disables Run/Settings/Delete,
and is labelled 'Inputs ready, starting run'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- install.sh: the CHANGE_ME check also matched the comment in
  .env.scenarios that mentions CHANGE_ME, so a public deploy was always
  refused even with every password set. Only settings lines are checked.
- prune_analysis.py built its own APIClient without an auth type, which
  oasislmf 2.5.9 can't authenticate (server_info 403), so the daily prune
  retried for 30 minutes and never deleted anything. It now uses the shared
  service-account login (env vars, then secrets.toml), so the password is
  no longer passed on the command line where it showed in the process
  list. The prune service also runs Python unbuffered so its log appears.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It built and pushed coreoasis/oasis_scenarios, which nothing uses since
the hosted demo is deployed with install.sh: scenarios/deploy_scenarios_ui.sh
builds the UI image on the server from the checked-out code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Feedback from reviewing the Scenarios app:

- Choosing a scenario: a filterable, sortable table (search, peril,
  country, provider, type) instead of text-heavy cards. Curated titles,
  perils, countries and types come from scenario_info in the Scenarios
  config, falling back to the exposure (OED peril and country names from
  the ods_tools OED spec). Fixes the missing Ghana-E760461 name (#28).
- PiWind removed from the Scenarios set (worker, portfolios, template,
  model_map): it isn't a scenario
- Sample results are the default in every output, with Analytical as the
  second option (MELT, MPLT, ALT/PALT, legacy ELT/AAL/PLT, comparisons)
- MELT, SELT and QELT get an Event selector when there's more than one
  event, applied to the table and the map
- Showcase runs break losses down by location (level 1, with maps) where
  the exposure has coordinates, plus the template's totals (level 2);
  add_showcase_analyses.py --replace rebuilds existing showcase runs
- Visitor runs default to a location breakdown when the exposure can be
  mapped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Treat 0,0 as not geocoded: one coordinate check (modules.oed.has_coordinates)
  for the maps, the showcase script and the run page's default breakdown
- Showcase runs break losses down by location when the exposure has
  coordinates, else by country when it spans several (EUWS), and are
  named with the curated scenario title
- Run summary as plain text, so long scenario names aren't truncated
- Key the summary level selector by analysis, so its labels update when
  switching runs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Showcase runs left over from scenarios removed from the config (PiWind)
no longer appear on the Showcase and Compare pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to map

- Heatmaps centre and zoom on the locations with a loss, using the
  north-south as well as the east-west spread (Philippines-Taiwan was
  centred on open sea, zoomed too far in)
- MELT, QELT, SELT and eltcalc only offer a Map tab when losses are grouped
  by location (with coordinates) or country, instead of 'No map to display.'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scenario data lives with the scenarios: remove scenario_info from the UI
config. Titles and descriptions come from each model's settings (updated in
the Scenarios repo), peril and countries from its exposure. Drops the
historical/synthetic type, which had no source in the scenario data.

Showcase runs are labelled with their scenario's current name, so renaming
a scenario doesn't need its showcase rebuilt. The test fixture's exposure and
settings now match its Moroccan earthquake scenario.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benhayes21
benhayes21 merged commit aecedb5 into fix/workflow-bugs Nov 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant