Documentation
¶
Overview ¶
Package sessioncleanup plans and runs the bulk deletion of a profile's archived session history: whole archived threads, or only their child sessions or subagents, picked by the day the thread was archived.
Index ¶
- Variables
- type ChoiceTotals
- type Counts
- type Deleter
- type Failure
- type FailureCode
- type Lister
- type Option
- type Plan
- type Request
- type Run
- type RunState
- type Scope
- type Selection
- type Service
- func (s *Service) Current(profileID string) (Run, bool)
- func (s *Service) Preview(ctx context.Context, request Request) (Plan, error)
- func (s *Service) Shutdown(ctx context.Context) error
- func (s *Service) Start(ctx context.Context, request Request) (Run, Plan, error)
- func (s *Service) Stop(ctx context.Context, profileID, runID string) (Run, error)
- type Thread
- type WorkspaceTotal
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRequest wraps every refused cleanup request. ErrInvalidRequest = errors.New("sessioncleanup: invalid request") // ErrRunActive refuses a second run for a profile whose cleanup is still running. ErrRunActive = errors.New("sessioncleanup: a cleanup is already running for this profile") // ErrNoActiveRun reports a stop request with nothing running. ErrNoActiveRun = errors.New("sessioncleanup: no cleanup is running for this profile") // ErrShuttingDown refuses new runs while the daemon stops. ErrShuttingDown = errors.New("sessioncleanup: service is shutting down") )
Functions ¶
This section is empty.
Types ¶
type ChoiceTotals ¶
ChoiceTotals are the per-check totals a picker shows beside each check.
type Counts ¶
type Counts struct {
// Sessions are archived main sessions (Everything only).
Sessions int
Children int
Subagents int
}
Counts is how many sessions a cleanup deletes, by kind.
type Deleter ¶
type Deleter interface {
DeleteArchived(ctx context.Context, target store.ArchivedSessionDelete) error
}
Deleter deletes one archived session through the normal session delete path. It must return store.ErrSessionNotFound for a session already gone and store.ErrSessionNotArchived for one restored or moved since the plan.
type Failure ¶
type Failure struct {
RootID string
WorkspaceID string
Title string
Code FailureCode
Message string
}
Failure is one thread that kept sessions the run meant to delete. Retrying it means a new run limited to RootID.
type FailureCode ¶
type FailureCode string
FailureCode classifies why a thread kept some of its sessions.
const ( FailureInstanceMain FailureCode = "instance_main" FailureDeleteFailed FailureCode = "delete_failed" )
type Lister ¶
type Lister interface {
ListSessionHistoryCleanupRows(
ctx context.Context,
query store.SessionHistoryCleanupQuery,
) ([]store.SessionHistoryCleanupRow, error)
}
Lister reads the archived history a cleanup plans from.
type Option ¶
type Option func(*Service)
Option configures a Service.
func WithConcurrency ¶
WithConcurrency bounds the threads deleted at once.
func WithDeleteTimeout ¶
WithDeleteTimeout bounds one accepted delete, including lifecycle lock admission. Nonpositive values retain the default timeout.
func WithProgressInterval ¶
WithProgressInterval sets the minimum gap between progress wakes.
func WithPublisher ¶
WithPublisher wakes clients of a profile when its run progresses or ends.
type Plan ¶
type Plan struct {
// CountedAt is the instant the plan counted up to: a session archived later
// is planned as still in the list, so a start sent with it deletes no more
// than the plan counted.
CountedAt time.Time
Counts Counts
// KeptLive counts child sessions still in the session list or in Later that
// the selection would otherwise delete; they and everything under them stay.
KeptLive int
// Choices are the totals each check alone would delete in the same range.
Choices ChoiceTotals
Workspaces []WorkspaceTotal
Threads []Thread
}
Plan is the dry run of one cleanup.
type Request ¶
type Request struct {
Scope Scope
Selection Selection
// ArchivedBefore picks threads whose main session was archived strictly
// before it; nil picks every archived thread.
ArchivedBefore *time.Time
// RootIDs, when set, narrows the picked threads to these main sessions (a retry).
RootIDs []string
// CountedAt, when set, is the instant of the dry run being confirmed: a
// session archived after it is planned as still in the list, so the cleanup
// deletes no more than that dry run counted.
CountedAt *time.Time
}
Request is one cleanup: what to delete, from which threads.
type Run ¶
type Run struct {
ID string
ProfileID string
Scope Scope
Selection Selection
ArchivedBefore *time.Time
// CountedAt is the plan's count: nothing archived later is in the run.
CountedAt time.Time
State RunState
// Total is every session the run planned to delete.
Total int
// Deleted counts sessions removed (or already gone).
Deleted int
// Skipped counts sessions restored or moved after the plan, so kept.
Skipped int
FailedThreads int
Failures []Failure
StartedAt time.Time
FinishedAt *time.Time
}
Run is a snapshot of one cleanup run.
type RunState ¶
type RunState string
RunState is where one cleanup run is.
const ( // RunRunning deletes in the background. RunRunning RunState = "running" // RunCompleted deleted every planned session. RunCompleted RunState = "completed" // RunPartial deleted some sessions; Failures name the threads that kept the rest. RunPartial RunState = "partial" // RunFailed deleted nothing; Failures say why. RunFailed RunState = "failed" // RunStopped ended on request or at daemon shutdown before finishing. RunStopped RunState = "stopped" )
type Scope ¶
Scope is the archived history one cleanup reads: one profile, in one workspace (or the user selector) or across all its workspaces.
type Selection ¶
Selection is what one cleanup deletes. Everything deletes each picked archived thread whole, so it includes the other two; without it, Children and Subagents thin the threads out and keep their main sessions.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service plans cleanups and runs at most one per profile in the background.
func NewService ¶
NewService builds a cleanup service over the archived history and the delete path.
func (*Service) Shutdown ¶
Shutdown stops admitting runs, stops the running ones, and waits for them.
func (*Service) Start ¶
Start plans a cleanup and deletes it in the background. The plan is frozen: sessions archived after it are never picked up by this run.
type Thread ¶
Thread is one picked archived thread and the sessions deleted from it, deepest first, so a failure part-way leaves every remaining session reachable from the thread's main session.
type WorkspaceTotal ¶
WorkspaceTotal is how many sessions a cleanup deletes in one workspace.