host: durable lazy sessions — logins survive a restart
Sessions were in-memory, so a restart logged everyone out (same class as the relation wipe). Move them to the durable store, but LAZILY so anonymous/crawler traffic doesn't spam it: session/create mints a sid with no row; the row appears on the first session/set (a login). A per-boot epoch (one durable write at startup, host/session-init!) keeps sids unique across restarts without a write per request. - lib/host/session.sx: lazy backend (create = no row, set = create row, exists = row written) + epoch/in-memory-counter sid generation. - serve.sh: point the session store at the durable backend + host/session-init!. - blog.sx: host/current-principal is now a durable read, so host/auth-footer (home + post footers) had to move OUT of the quasiquote into let bindings — a perform during page-tree build raises VmSuspended (the whole site 500'd for a beat). Principal computed once per page. - 2 session tests: create writes no row, set creates the row. 249/249. Verified live: site renders (anon + authed), login + footer survive a container force-recreate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -111,11 +111,18 @@ EPOCH=1
|
||||
echo "(epoch $EPOCH)"
|
||||
echo "(eval \"(host/blog-load-edges!)\")"
|
||||
EPOCH=$((EPOCH+1))
|
||||
# Session signing secret + admin login credentials, then grant the admin
|
||||
# principal "edit" on "blog" so a logged-in session passes the ACL gate on the
|
||||
# write routes. Sessions stay IN-MEMORY (default store) — logins reset on
|
||||
# restart but the durable KV isn't spammed by anonymous/ crawler sessions
|
||||
# (lazy session creation is a future lib/dream/session.sx improvement).
|
||||
# Sessions on the DURABLE store, LAZILY: only a logged-in session (one that
|
||||
# writes a field) persists, so a login survives a restart while anonymous /
|
||||
# crawler traffic leaves no rows. host/session-init! bumps the per-boot epoch
|
||||
# that keeps sids unique across restarts. Then the signing secret + admin
|
||||
# credentials, and grant admin "edit" on "blog" so a logged-in session passes
|
||||
# the ACL gate on the write routes.
|
||||
echo "(epoch $EPOCH)"
|
||||
echo "(eval \"(host/session-use-store! (persist/durable-backend))\")"
|
||||
EPOCH=$((EPOCH+1))
|
||||
echo "(epoch $EPOCH)"
|
||||
echo "(eval \"(host/session-init!)\")"
|
||||
EPOCH=$((EPOCH+1))
|
||||
echo "(epoch $EPOCH)"
|
||||
echo "(eval \"(host/session-set-secret! \\\"$SESSION_SECRET\\\")\")"
|
||||
EPOCH=$((EPOCH+1))
|
||||
|
||||
Reference in New Issue
Block a user