[Session] History management — token budget, expiry cleanup, clear endpoint #40
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
What
Three related housekeeping concerns for session conversation history:
session_messagesrows when a session expiresDELETE /api/sessions/:id/historyendpoint so users can manually clear contextDepends on: #38 (session_messages table), #39 (context injection)
1 — Token budget enforcement
The
getSessionHistoryhelper from #38 should already trim messages to the budget. Add a guard insessions.tsto log a warning if the returned history still exceeds the budget (defensive check only — do not hard-fail the request).2 — Expiry cleanup
When a session is marked
expired(inGET /sessions/:idline ~228), also delete its history rows:This keeps the DB lean — expired sessions are dead anyway.
3 — Clear endpoint
Add a new route to
artifacts/api-server/src/routes/sessions.ts:Authorization: Bearer <macaroon>header (same as/request)activeorpaused— reject expired/missing sessionssession_messagesrows for the session200 { cleared: true, sessionId }Register the route in the Express router (already mounted at
/api).Relevant files
artifacts/api-server/src/routes/sessions.tspackages/db/src/index.tspackages/db/src/schema.tsAcceptance
session_messagesrowsDELETE /api/sessions/:id/historyreturns 200 and clears rowsDELETEwith a bad macaroon returns 401DELETEon an expired session returns 410PR #100 created.
Implemented the following: