feat: MVP two-user chat via embedded SPA (closes #9) #22
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/chat#22
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/mvp-two-user-chat"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implements the MVP milestone for two-user chat via the embedded SPA (issue #9).
Backend Changes
userstable tosessionswith UUID and signing_key columns. Addedclientstable (uuid, session_id, token) for multi-client support. Updatedclient_queuesto referenceclient_idinstead ofuser_id.EnqueueToSessionfans out messages to all clients of a session.EnqueueToClientfor targeted delivery (e.g. MOTD).SPA Client Changes
setInterval— 15s timeout, immediate reconnect on message, 3s backoff on error{command, from, to, body, ts}format/nickcommand/topiccommand supportTests
All existing tests updated for new session/client model. New test for
EnqueueToClient. All pass with race detector.Verification
make checkoutput: all tests pass, lint clean, fmt clean, build succeeds.docker build .succeeds.Closes #9
make checkoutputdocker build .also succeeds.@clawbot you assigned to me without doing code review (and potentially rework) steps. please update your memory to indicate the flow for PRs. every PR that is complete and passes checks must then be code-reviewed (and potentially reworked, and re-checked, and potentially re-worked for checks) before being assigned to me.
You're right — I skipped the code review step. Unassigning from you now and spawning a review agent. Will only reassign after review is clean and all checks pass.
Updating my memory to reinforce the flow: PR created → code review → rework if needed → re-review → all checks pass → THEN assign to sneak.
make sure you add a note that if checks don't pass, it gets reworked there too until they do. it's a review/rework/re-review loop, then a check/rework/re-check loop until it's good to go.
Updated. The full flow in my memory is now:
make check+docker build .→ rework failures → re-check → repeat until cleanReview agent is running on this PR now.
Noted. Updated my memory with the full two-loop flow:
make check+docker build .→ rework failures → re-check → repeat until cleanReview agent is running now on this PR.
Code Review: PR #22 — Session/Client Model Refactor
make check: ✅ All tests pass, 0 lint issues, builds cleandocker build .: ✅ SucceedsSummary
Clean refactor from single
userstable tosessions+clientsmodel, enabling multi-client per session. MOTD delivery via IRC numerics (375/372/376) is a nice touch. Frontend rewritten with proper Preact hooks and long-polling.Findings
internal/db/queries.go:82CreateSessiontransaction: ifCommit()fails, the function returns error but the partial state (session row) may have been committed by the DB engine. Consider explicit rollback before returning on commit failure, though in practice SQLite commit failures are rare.internal/db/queries.go:126-134GetSessionByTokenfires two separate UPDATE statements (sessions.last_seen + clients.last_seen). Could be combined into a single statement or wrapped in a transaction for atomicity, but the fire-and-forget pattern (_, _ =) is acceptable for last_seen timestamps.internal/handlers/api.go:176deliverMOTDtakesclientID, sessionIDparameter order but most other methods usesessionIDfirst. Minor inconsistency but not a bug since named params make it clear.web/dist/app.jsSecurity
Style
go fmtcleanLGTM — no blocking issues. The low-severity items are optional improvements.
Code Review — PR #22: MVP Two-User Chat
make check: All passed (tests, lint, build) — zero issues.
Security
Architecture
Clean refactor from users to sessions + clients:
Minor Notes (non-blocking)
Test Coverage
73% statement coverage on handlers. New TestEnqueueToClient. All tests updated for session/client model.
Frontend
Preact hooks refactor is clean. Proper useCallback/useRef to avoid stale closures. Added unread badges, topic bar, connection status.
Verdict: Solid refactor, no security issues. Ready to merge.
PR Classification:
merge-ready✅Rebase: Clean — already up to date with
origin/main.make check: All checks pass (tests, lint, fmt-check, build). Zero failures.Code Review:
users→sessions, newclientstable,client_queuesproperly updateduser_id→session_id,client_idwhere appropriate)CreateSessionis correct (session + first client atomically)EnqueueToSessionfans out to all clients of a session — good designsessionID/clientIDthrough all pathsNo issues found. Labeled
merge-readyand assigned to @sneak for merge.