perf(sessions): push new-session detection over SSE #181
No reviewers
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman!181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/push-new-sessions"
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?
Problem
New sessions only appeared on the next list-poll tick — ~9s worst case (4s background refresher + 3–5s frontend poll) — because session creation was never broadcast. Detection relied entirely on polling OpenCode's SQLite DB.
Approach
Reuse infrastructure that already exists:
/eventSSE stream./api/eventsbroadcast hub and the frontenduseGlobalEventslistener already exist.On the first sighting of a
session.updatedevent for a given session ID, the watcher invalidates the sessions cache and broadcasts a newocman.session.changedevent. The frontend invalidates the['sessions']query, so the list refetches immediately instead of waiting for the next poll.A seen-set dedupes
session.updated(which fires per turn/token) so only the first sighting — i.e. "a session appeared" — triggers work. Per-keystroke updates are dropped.Result
Changes
Backend
autoapprove.go—session.updateddispatch case +dispatchSessionChanged→onSessionChangedtee callback.autoapprove_watcher.go—handleSessionChangedwith seen-set dedup; busts cache + broadcasts on first sight.broadcast.go—broadcastSessionChanged→ocman.session.changed.models_cache.go—InvalidateSessionsCache()(expires entries, keeps last-good for stale-on-busy).Frontend
useGlobalEvents.ts—ocman.session.changedlistener +onSessionChangedregistry.App.tsx— invalidates['sessions']on the event.Tests
session.updated(envelope/flat/both casings/missing-id).InvalidateSessionsCacheforces a refetch.All Go + frontend suites,
go vet,tsc, ESLint, and the platform-branching check pass.Known limitations
ponytail:comment); swap to LRU if per-machine session count ever grows large.Coverage ratchet: ✅ pass
Tolerance: -0.1%. Baseline stored on
gh-pages.