Skip to content

fix(demo): keep a demo in use and serialise boots - #47

Merged
Vishwas1345 merged 2 commits into
mainfrom
fix/demo-reset-race
Oct 16, 2026
Merged

Vishwas1345 merged 2 commits into
mainfrom
fix/demo-reset-race

Conversation

@Vishwas1345

Copy link
Copy Markdown
Owner

Why

The deploy of dab06b6 failed at boot. Render's zero-downtime deploy ran the new container beside the live one, both on the same Neon database, and each boot's reset (#42) dropped the schema under the other:

07:02:16 All migrations have been successfully applied.
07:02:19 operator seed failed: The table `public.Operator` does not exist
07:02:21 Exited with status 1
07:02:22 demo database reset (another container)

The site stayed up on the previous version and reseeded, but every deploy risked it. My #42 tests only ever ran one container.

What

  • prepare-demo.ts replaces reset-demo.ts: under one Postgres advisory lock (single connection), reset if idle, migrate, seed the operator and the scenario. Boots now run one after the other.
  • resetDemoDatabase(db, idleSince) returns empty | kept | reset: a demo with audit activity in the last DEMO_RESET_IDLE_MINUTES (default 10) is kept. Waking from sleep (15+ idle minutes) still resets; a deploy beside a demo in use keeps it; a second boot sees the first one's seed. All earlier guards stay.
  • deploy/start.sh runs it before starting the processes.
  • scripts/deploy-image-smoke.sh now starts two containers at once on one database (one empty, one kept, both serving, 40 labs once), then a third past the idle threshold must reset.

Verified

  • Integration on a throwaway DB: kept when recent, reset when idle, refusal intact, and two locked boots never overlap. Mutation-checked: removing the lock or the idle check fails a test.
  • The smoke reproduces the incident: with the lock removed it fails with empty empty; with it, passes (147 MB).
  • lint, typecheck, unit (693 api, 141 web), integration 241 twice on a fresh DB, api coverage 98.4%; links resolve.

Known limit

A deploy during an idle stretch (no activity for 10 minutes) still resets under the old container, which sees missing tables for seconds while it is being replaced. Acceptable for a demo; recorded in GAPS and AGENTS.

After merge this is also the first commit under checksPass: Render should start the deploy only after CI passes.

🤖 Generated with Claude Code

Vishwas1345 and others added 2 commits October 16, 2026 12:44
A deploy runs the new container beside the live one on the same database.
Each boot's reset dropped the schema under the other: on 2026-10-16 the new
container's operator seed found no Operator table and the deploy failed.

prepare-demo replaces reset-demo and holds a Postgres advisory lock through
reset, migrate and both seeds, so boots run one after the other. The reset
now keeps a demo with activity in the last DEMO_RESET_IDLE_MINUTES (default
10): waking from sleep still starts fresh, a deploy beside a demo in use keeps
it, and a second boot sees the first one's seed. The image smoke now starts
two containers at once on one database; without the lock it fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vishwas1345
Vishwas1345 merged commit d715769 into main Oct 16, 2026
10 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