feat: SSE event stream for frontend + agent log shipping#247
Merged
Conversation
d168c62 to
132a24a
Compare
Add a multiplexed SSE endpoint (GET /frontend/events/stream) that the frontend can subscribe to for live updates: agent status, acquisition progress, instruction lifecycle, processing metrics, and agent logs. Agent-side changes add a RemoteLogHandler that buffers and ships INFO+ logs to a new ingestion endpoint, persisted in an AgentLog table with configurable retention (default 7 days). Closes #246
Use standard SQLAlchemy index naming (ix_{table}_{col}) instead of
custom names so autogenerate doesn't detect phantom drift. Declare
composite index in __table_args__ so it's part of the metadata. Fix
column nullability to match model declarations.
…e head After merging PR #243, the head revision advanced from a1b2c3d4e5f6 to b2c3d4e5f6a7 (consolidated foilhole groups migration). Repoint this branch's migration at the new head so alembic sees a single linear chain instead of two divergent heads.
Adapts PR 247 to the new AsyncSession foundation that landed in #266-271: - frontend_stream.py: 5 query helpers now take AsyncSession and use await db.execute(...).scalars()/.all(). Single-column selects use scalar_one() for the count() queries. - api_server.py: ingest_agent_logs and frontend_event_stream switched from SqlAlchemySession to AsyncSession. - frontend_event_stream's async generator was calling sync db.query via the helpers - the same deadlock pattern PR 268 fixed for stream_instructions. Now awaits all helper calls. - consumer.py: re-applies the micrograph.updated_at update inside the new async motion-correction and CTF handlers. 170 passed, 3 skipped (was 158+3 on main; +12 from PR 247's pydantic model tests). pyright api_server.py 169 vs 170 baseline (-1).
132a24a to
475cd78
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /frontend/events/streamwith query param filtering (acquisition_uuid,agent_id,event_types)POST /agent/{agent_id}/session/{session_id}/logswith batch supportRemoteLogHandleron agent side that buffers and ships INFO+ logs every 5sAgentLogDB table with auto-increment cursor for efficient streaming, plus log retention cleanup (default 7 days)Micrograph.updated_atfor processing metric change detectionupdated_atin consumer when motion correction and CTF results arriveEvent types streamed
agent.statusAgentConnection+AgentSessionacquisition.progressinstruction.lifecycleAgentInstruction+ acknowledgementsprocessing.metricMicrographwhereupdated_at > last_pollagent.logAgentLogtable (cursor-based)heartbeatDB migration
Alembic migration
b3c4d5e6f7a8addsagentlogtable andmicrograph.updated_atcolumn.Test plan
curl -N http://localhost:8000/frontend/events/streamwith backend runningagent.logevents in SSE streamCloses #246
Related frontend work: DiamondLightSource/smartem-frontend#65