fix(routes): remove duplicate GET /api/sessions shadowing session_list() #17
Reference in New Issue
Block a user
Delete Branch "fix/sessions-route-dedup"
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
route_sessions()function that searched engram forsession-start— a label never written by the currentsession_create(). This caused everyGET /api/sessionsrequest to return[], making the sidebar appear empty after a daemon restart.GET /api/sessionsif-block inhandle_requestthat calledroute_sessions(). The surviving handler (previously dead code) now calls the correctsession_list()fromsessions.el.DELETE /api/sessions/:idroute wired tosession_delete().PATCH /api/sessions/:idroute wired tosession_update_patch().Test plan
GET /api/sessionsreturns real sessions after daemon restartDELETE /api/sessions/:idremoves session from engramPATCH /api/sessions/:idupdates title and/or folderThe core fix is correct and necessary. The old
route_sessions()function usedengram_search_json("session-start", 20)— wrong label ("session-start"vs"session:meta"), wrong limit (20 vs 50), and no filtering — soGET /api/sessionswas silently returning wrong/empty results for clients using the new sessions system. Removing it and letting the realsession_list()handler (already present further down the GET chain) take over is the right call. The DELETE and PATCH routing additions are also correct and complete a gap between whatsessions.elexported and whatroutes.elwired up.One blocker to fix before merge:
session_deleteinsessions.eldoes not invalidate thesession_indexstate cache. After a successful DELETE,session_list()will serve the deleted session from the fast-path state cache (state_get("session_index")) until the daemon restarts. This was latent before — DELETE had no route. Now that you've wired up DELETE routing, the stale-list bug is immediately observable.Fix: add
state_set("session_index", "")insession_deletebefore its return, matching the pattern thatsession_update_patchalready uses correctly (line 290 ofsessions.el).Everything else looks good — the ID extraction logic for DELETE and PATCH is consistent with the existing GET/POST session handlers,
session_update_patchcorrectly invalidates the cache, and there are no new shell-injection surfaces introduced.session_delete cleared the per-session state (session_hist_ and session_node_) but not the shared session_index cache. The next call to session_list() hit the fast path (state_get("session_index")) and returned the deleted session until the daemon restarted. session_update_patch already called state_set("session_index","") to force a re-fetch from Engram; session_delete now does the same. Add tests/test_sessions.el covering: - session_title_from_message (pure function, all edge cases) - session_make_content (JSON structure and required session:meta marker) - DELETE cache invalidation: session_index cleared, fast path disabled - PATCH cache invalidation: stale title/folder not returned via fast path - GET /api/sessions: session_list() fast path returns session_index (confirms removal of the stale route_sessions() engram stub)