Avoid repeated expensive work when evaluating automatic session cleanup
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Problem
Automatic session cleanup can repeatedly evaluate the same unchanged sessions, including sessions that remain non-actionable because a related pull request is still open or a retained worktree cannot yet be cleaned up. These sessions can be reconsidered at startup and every hourly lifecycle pass, resulting in duplicated work and repeated GitHub requests.
The evaluation itself also appears substantially more expensive than necessary. In particular, the lifecycle can call `restoreSession`, which materializes the provider chat, reads the session database, reconstructs the full message history, and may warm the provider session catalog when direct metadata resolution fails. Resuming or fully restoring a session should be avoided unless it is strictly necessary, especially for a background eligibility check.
## Expected direction
Optimize automatic cleanup so that:
- unchanged, non-actionable sessions do not repeatedly incur the same expensive evaluation;
- eligibility checks use the cheapest authoritative data available and avoid restoring sessions when unnecessary;
- duplicated GitHub and provider work is minimized, including when multiple sessions reference the same pull request;
- archive and delete operations still perform the required authoritative validation immediately before taking action;
- failures continue to fail closed.
The specific caching, backoff, event-driven reevaluation, deduplication, or lifecycle design should be decided by the feature owner.
Related: #334341, #335840
(Written by Copilot)
Contributor guide
Assessment
This issue has not been assessed yet.