sessionindex

package
v0.34.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultReapGuard added in v0.34.6

func DefaultReapGuard(row types.SessionListItem) bool

DefaultReapGuard is the message_count == 0 safety guard.

func PlanReconciliation added in v0.34.6

func PlanReconciliation(indexRows []types.SessionListItem, harnessList func() (map[string]bool, error), prevMiss map[string]int, threshold int, reap ReapGuard) (remove, keptForOperator []string, nextMiss map[string]int)

PlanReconciliation is the #1340 convergence decision (S5b): given the index's session IDs, a harness-list provider, and the previous consecutive-miss counters, it returns which rows to DELETE now and the next counters. Pure — orchestration (adapter call, counter storage, deletion) lives with the proxy handler; this function IS the invariant:

  • harness present → keep, counter cleared
  • harness absent → counter+1; removal at threshold consecutive misses (N=2 survives one mid-restart snapshot miss)
  • harness call error → keep everything, counters frozen (an unreachable pod is NOT evidence of deletion)
  • counters for rows no longer indexed are dropped (bounded state)

The lister returning an error models the entire check failing: no session is treated as absent on a failed check.

ReapGuard is the #1340 triage safety rule: auto-deletion only removes rows the guard admits (message_count == 0 — the never-persisted / probe-shell class). Rows the harness reports gone but that carry message history are returned as keptForOperator instead: a vanished session WITH history may indicate a harness store reset, so the row is surfaced (the orchestration layer records the session_index_reconcile_outcomes_total metric + a Warn log) rather than silently destroyed. threshold <= 1 removes on the first absence; callers pass 2. keptForOperator rows carry no miss counter here — the orchestration layer pins theirs at the threshold so the signal repeats consistently.

func ReconcileOutcome added in v0.34.6

func ReconcileOutcome(outcome string)

ReconcileOutcome records one convergence disposition (handler-side).

func ReconcileOutcomeForTest added in v0.34.6

func ReconcileOutcomeForTest(outcome string) prometheus.Counter

ReconcileOutcomeForTest reads a disposition counter (test assertions).

Types

type ReapGuard added in v0.34.6

type ReapGuard func(types.SessionListItem) bool

ReapGuard admits an index row for auto-deletion. The default guard (#1340 triage): only rows with no message history (message_count == 0).

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages the session_index table with non-blocking writes.

func New

New creates a new SessionIndexService.

func (*Service) DeleteByWorkspace

func (s *Service) DeleteByWorkspace(ctx context.Context, workspaceID string) error

DeleteByWorkspace removes all session index entries for a workspace.

func (*Service) DeleteSession

func (s *Service) DeleteSession(ctx context.Context, workspaceID, sessionID string) error

DeleteSession removes a single session and its descendants from the session index.

func (*Service) ListByWorkspace

func (s *Service) ListByWorkspace(ctx context.Context, workspaceID string) ([]types.SessionListItem, error)

ListByWorkspace returns session metadata ordered by last_message_at DESC.

func (*Service) RebuildMessageCount added in v0.34.6

func (s *Service) RebuildMessageCount(ctx context.Context, workspaceID, sessionID string, count int) error

RebuildMessageCount sets a session's message_count absolutely from the harness-walked ground truth (#1481) — the reconcile-side repair for the incremental path's duplicate-event double-count. The DB-level DISTINCT guard keeps converged workspaces write-free.

func (*Service) RecordMessage

func (s *Service) RecordMessage(workspaceID, sessionID, title string, at time.Time)

RecordMessage is non-blocking: pushes to a bounded channel. If the channel is full, the oldest event is dropped.

func (*Service) Start

func (s *Service) Start() error

Start begins the background drainer goroutine.

func (*Service) Stop

func (s *Service) Stop() error

Stop signals the drainer to stop and waits for it to finish.

func (*Service) UpdateLastSeen

func (s *Service) UpdateLastSeen(ctx context.Context, workspaceID, sessionID string) error

func (*Service) UpsertContextUsed

func (s *Service) UpsertContextUsed(ctx context.Context, workspaceID, sessionID string, contextUsed int64) error

UpsertContextUsed persists the prompt token count from the most recent LLM step for this session. Called synchronously from the proxy's onRawEvent handler on every adapter-declared usage event. Low frequency (at most once per LLM call), so a direct synchronous write is appropriate.

func (*Service) UpsertParent

func (s *Service) UpsertParent(ctx context.Context, workspaceID, sessionID, parentID string) error

UpsertParent records the parent session of a (sub)session. Used by the proxy to mirror opencode's session.parentID into the sidebar's session_index so the sidebar can render hierarchy without round-tripping the agent. Empty parentID is allowed (top-level session) but uncommon — callers typically only invoke this when they have observed a non-empty parentID on a session.

func (*Service) UpsertTitle

func (s *Service) UpsertTitle(ctx context.Context, workspaceID, sessionID, title string) error

UpsertTitle updates just the title for a session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL