5527b25e52c2fa72e34cb7f2fc3a35eac03c5089
Root cause, confirmed live against Postgres and reproduced end-to-end through two real WebSocket connections: ws/chat.py shares one AsyncSession for a whole connection's lifetime. A read-only action (e.g. a "join" frame's membership check) can leave a transaction open with nothing to commit it until the next write. Postgres's now()/CURRENT_TIMESTAMP returns that transaction's *start* time in that case, not the actual statement's -- so a reply sent after any idle/reading period got timestamped to when the idle period started, sorting it before messages that were genuinely sent earlier. This is independent of the two earlier #45 fixes (missing ORDER BY tiebreakers, a stale-response race on reload) -- both were real bugs, but this was the actual mechanism behind "my message appears before theirs even though theirs was sent first." Switched Message.created_at and MessageReaction.created_at from func.now() to func.clock_timestamp(), which always reflects the actual moment of execution regardless of how long the transaction has been open. Migration is a plain column-default change -- no table rewrite, no lock risk, round-trips cleanly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
DS Chat
A web-based team chat service (Mattermost-style, no threaded conversations), invite-only. See ARCHITECTURE.md for the full system design and phased build plan.
Phase 1: auth, open-room CRUD, and single-instance WebSocket chat, backend
- a minimal frontend. Phase 2: private rooms, room roles (owner/admin/ member), and room invites — backend only, see below. Later phases (push notifications, Redis fan-out, the admin portal, the bot/extension system, and production deployment) are tracked as issues in the repo's issue tracker, prioritized.
Structure
backend/— FastAPI + SQLAlchemy 2.0 (async) + PostgreSQL. Seebackend/README.mdfor local setup, migrations, how to create a user (site registration is invite-only — no public sign-up endpoint), and the Phase 2 room-roles/invites API.frontend/— React + Vite PWA (login, room list, chat view). Still Phase-1-only: it doesn't yet call any of the Phase 2 endpoints. A UI redesign is happening separately; frontend work resumes once that lands.
Quickstart
# 1. Postgres (see backend/README.md for details)
docker run -d --name ds-chat-postgres \
-e POSTGRES_USER=ds_chat -e POSTGRES_PASSWORD=ds_chat -e POSTGRES_DB=ds_chat \
-p 5432:5432 postgres:16-alpine
# 2. Backend
cd backend
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
cp .env.example .env # then set SESSION_SECRET
.venv/bin/alembic upgrade head
.venv/bin/python -m app.cli create-user alice alice@example.com "some-password"
.venv/bin/uvicorn app.main:app --reload &
# 3. Frontend (in another shell)
cd frontend
npm install
npm run dev
Then open http://localhost:5173 and log in with the account created above.
The Vite dev server proxies /api and /ws to the backend on :8000, so no
CORS configuration is needed in development.
Deployment
See DEPLOYMENT.md for the full production runbook — two Debian 13 servers, no containers, matching ARCHITECTURE.md §9.