Backend:
- Session.last_subscriber_left_at: monotonic timestamp set when last SSE subscriber
leaves, cleared when a new one arrives
- Session.subscriber_count(): replaces len(_subscribers) access from outside the model
- session_store._reaper_loop(): kills sessions with no subscribers for >SESSION_IDLE_TTL_S
(default 90s); runs every TTL/2 seconds via asyncio.create_task at startup
- session_store._reaper_loop_once(): single-cycle variant for deterministic tests
- app/main.py lifespan: starts reaper on startup, cancels it cleanly on shutdown
- config.py: SESSION_IDLE_TTL_S setting (90s default, overridable per-env)
Frontend:
- useWakeLock.ts: Screen Wake Lock API wrapper; acquires on connect, releases on
disconnect; degrades silently when unsupported (battery saver, iOS Safari)
- useToneStream.ts: visibilitychange handler — on hidden: closes EventSource without
ending backend session (grace window stays open); on visible: GET /session/{id}
liveness check, reconnects SSE + re-acquires wake lock if alive, sets expired=true
and calls store.reset() if reaped
- ComposeBar.vue: surfaces expired state with calm 'Session timed out' notice
(not an error — expected behaviour on long screen-off)
Tests:
- test_reaper.py: 7 tests covering subscriber idle tracking, reaper eligibility
(kills idle, spares active subscriber, spares within-TTL)
28 lines
881 B
Docker
28 lines
881 B
Docker
FROM python:3.12-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# System deps for audio inference (cf-voice real mode only)
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libsndfile1 git \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# GIT_TOKEN: Forgejo token for private circuitforge-core install.
|
|
# Passed at build time via compose.cloud.yml build.args — never baked into a layer.
|
|
ARG GIT_TOKEN
|
|
|
|
# Install public sibling + private circuitforge-core (token consumed here, not cached)
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt && \
|
|
pip install --no-cache-dir \
|
|
"git+https://${GIT_TOKEN}@git.opensourcesolarpunk.com/Circuit-Forge/circuitforge-core.git@main"
|
|
|
|
COPY pyproject.toml .
|
|
RUN pip install --no-cache-dir -e . --no-deps
|
|
|
|
COPY app/ app/
|
|
|
|
ENV CF_VOICE_MOCK=1
|
|
EXPOSE 8522
|
|
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8522"]
|