sessionactivity

package
v0.0.255 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sessionactivity reports the live phase of an agent session.

Eluc (and any other caller) should use Read rather than re-implementing per-runner log scans. Kinds are idle, thinking, responding, tool_calling, waiting, error, aborted, and not_found.

DSH phases are composed from three independent observations, because no single one covers every session: the agent registry says whether a turn is running, but only for the sessions a daemon has loaded; the folded session log says whether the newest turn ever closed, for any session with a log; and the log's write lease tells an open turn that is still executing from one whose process is gone. A session the registry does not list is therefore not idle: it is an interrupted error when its log left a turn open and no writer holds the lease, a running turn when a writer does, and an Unanswered placeholder when the log has not been folded yet. not_found means the log is gone, never merely "not loaded by the daemon".

Index

Constants

View Source
const (
	RunnerDSH   = "dsh"
	RunnerGrok  = "grok"
	RunnerCodex = "codex"
)
View Source
const (
	// DetailInterrupted marks a turn the log closed as interrupted, or an open
	// turn whose writer is gone.
	DetailInterrupted = consumers.OutcomeInterrupted
	// DetailLogAhead marks an open turn newer than the status answer: the answer
	// could not testify about it. It is a placeholder, not a phase.
	DetailLogAhead = "turn state is newer than the status answer"
	// DetailWriterUnknown marks an open turn whose write lease could not be
	// observed. It is a placeholder, not a phase.
	DetailWriterUnknown = "session writer is not known"
	// DetailNotFolded marks a session whose folded turn state is not usable yet.
	// It is a placeholder, not a phase.
	DetailNotFolded = "session outcome not folded yet"
	// DetailUnreadable marks a log the readers could not read at all. It is a
	// placeholder, not a phase.
	DetailUnreadable = "session log is unreadable"
	// DetailTurnOpen marks an error whose turn never ended because the process
	// that ran it is gone. It is shared with the tail classifier so both depths
	// report the death identically.
	DetailTurnOpen = dshsessions.DetailTurnOpen
)

Details the DSH readers report when a turn did not end because the provider answered. They are constants because callers must tell such a turn from a provider failure: auto-retry has nothing to re-send for a turn nobody answered.

Variables

This section is empty.

Functions

func ClosedTurns added in v0.0.247

func ClosedTurns(runner, sessionID string) int64

ClosedTurns is how many turns a session's log has closed. It is the number a caller records before handing over a prompt, so WaitAfter can tell the round it asked for from the one before it.

func IsLivenessDetail added in v0.0.238

func IsLivenessDetail(detail string) bool

IsLivenessDetail reports whether a Detail describes the turn's liveness rather than a failure the provider reported. Such a turn got no answer, so retry automation has nothing to re-send and no rule should match it.

func SetDefaultOutcome added in v0.0.238

func SetDefaultOutcome(fn DurableOutcomeSource)

SetDefaultOutcome installs the process-wide DurableOutcomeSource that the default DSH reader consults; a nil hook uninstalls it and leaves the folded turn state unknown, which makes the reader abstain rather than guess.

Only the DSH reader consults it. Grok and Codex report liveness from their own registries, so installing a hook can never change their answer.

func SetDefaultRunStatus added in v0.0.225

func SetDefaultRunStatus(fn RunStatus)

SetDefaultRunStatus installs the process-wide RunStatus that package-level Read and Follow consult for DSH Sessions; a nil hook uninstalls it and leaves DSH liveness unknown until a hook is installed again.

Only the DSH reader consults it. Grok and Codex report liveness from their own registries, so installing a hook can never change their answer. Install it before reading: a hook decides which daemon answers, and a Session ID is answered only by the daemon that loaded it.

func SetDefaultWriter added in v0.0.238

func SetDefaultWriter(fn WriterSource)

SetDefaultWriter installs the process-wide WriterSource that tells the DSH reader whether a session's write lease is still held; a nil hook uninstalls it, and the reader then abstains from calling an open turn dead.

Types

type DurableOutcome added in v0.0.238

type DurableOutcome struct {
	// Known is false before the fold has read the session at all. It is not
	// "idle": no fold means the turn state was never observed.
	Known bool
	// Current is whether the fold consumed the whole log as of Modified. A fold
	// that is behind cannot testify about the newest turn, so its Running is a
	// statement about the past, not about now.
	Current bool
	// Running is whether the newest turn/start has no matching turn/end yet.
	Running bool
	// Last is the end kind of the last closed turn: completed, aborted,
	// interrupted, max-tokens, error. Empty when no turn has closed.
	Last string
	// Turns is how many turns closed. It makes "the fold saw the end of the
	// turn the answer was about" a comparison rather than a guess.
	Turns int64
	// Modified is the log's last write, sampled with the fold. The readers
	// order it against Lookup.At: an answer sampled before the newest write
	// cannot testify about the turn that write opened.
	Modified time.Time
}

DurableOutcome is what a session's own log says about its turns, folded by a consumer bus instead of read from the tail.

Liveness and the log are sampled independently and either one can be silent. session/status knows only the sessions a daemon has loaded, so for any other session it cannot say whether a turn is running — and a log that stops looks the same whether the turn is still executing, the process was killed, or the daemon started elsewhere. A fold closes that gap because it consumed every row up to its own Size: it knows whether the newest turn/start still has no turn/end, and the writer lease says whether anyone is still writing that log. An open turn nobody writes is a turn that will never close.

type DurableOutcomeSource added in v0.0.238

type DurableOutcomeSource func(sessionID string) DurableOutcome

DurableOutcomeSource answers one session's folded turn state. A zero value means the source has no usable fold for the session, never that the session is idle.

type Kind

type Kind string

Kind is the live phase of one session.

const (
	Idle        Kind = "idle"
	Thinking    Kind = "thinking"
	Responding  Kind = "responding"
	ToolCalling Kind = "tool_calling"
	Waiting     Kind = "waiting"
	ErrorKind   Kind = "error"
	Aborted     Kind = "aborted"
	NotFound    Kind = "not_found"
)

func ClassifyChat

func ClassifyChat(lastKind, tool string, live bool) (Kind, string)

ClassifyChat maps a grok/codex last coalesced message onto the five activity kinds. live is PID liveness, not "the TUI is still open".

type Lookup added in v0.0.229

type Lookup struct {
	Running  bool
	Present  bool
	Answered bool
	// At is when the answer was sampled. A cached hook reports the batch's
	// instant, so this can be older than the call: the readers compare it with an
	// open turn's start instead of assuming both reads are simultaneous.
	At time.Time
}

Lookup is one Session's answer from session/status.

Answered is whether the daemon replied. Present is whether this id was in the map. Running is the map value when Present.

The map only holds sessions the daemon has loaded, so absence is not evidence that a session is idle: a session whose daemon was restarted, or one running in a standalone TUI, is absent while its log may still hold an open turn. Absence therefore says only that no daemon process runs the turn, and the readers decide the phase from the folded log and the write lease instead. Present with Running false still reads the tail; not_found is reserved for a log the store cannot find at all, and an unanswered RPC is error.

type Probe

type Probe struct {
	DSH   func(sessionID string) (Snapshot, error)
	Grok  func(sessionID string) (Snapshot, error)
	Codex func(sessionID string) (Snapshot, error)

	// RunStatus decides liveness for the default DSH reader when set; nil uses
	// the installed default from SetDefaultRunStatus. It does not apply when DSH
	// is set, because that reader answers liveness itself, and it never applies
	// to Grok or Codex.
	RunStatus RunStatus

	// Outcome and Writers complete that reader's verdict: whether the newest
	// turn in the folded log closed, and whether a process still holds the log's
	// write lease. Nil uses the installed defaults from SetDefaultOutcome and
	// SetDefaultWriter, and a missing hook makes the reader abstain rather than
	// call a turn dead. Like RunStatus they do not apply when DSH is set, and
	// they never apply to Grok or Codex.
	Outcome DurableOutcomeSource
	Writers WriterSource
}

Probe is the injectable entry point. Nil fields use the live agent homes.

func Default

func Default() Probe

Default is the production probe: every nil field reads the live agent home, and the DSH reader therefore also consults the installed RunStatus, Outcome and Writer hooks.

func (Probe) Follow

func (p Probe) Follow(runner, sessionID string, afterSeq int64, tail int) (Snapshot, []dshsessions.TranscriptRow, error)

Follow returns activity plus a committed transcript tail.

func (Probe) Read

func (p Probe) Read(runner, sessionID string) (Snapshot, error)

Read reports one session's activity.

type RunStatus added in v0.0.225

type RunStatus func(sessionID string) Lookup

RunStatus answers whether one Session is executing a turn right now, as the runner's own agent registry sees it. A silent hook (nil, failed RPC) leaves Answered false. An id missing from a successful map is Present false.

type Snapshot

type Snapshot struct {
	Runner    string `json:"runner"`
	SessionID string `json:"session_id"`
	Kind      Kind   `json:"kind"`
	Detail    string `json:"detail,omitempty"`
	Live      bool   `json:"live"`
	Workspace string `json:"workspace,omitempty"`
	Title     string `json:"title,omitempty"`
	UpdatedAt int64  `json:"updated_at,omitempty"`
	Outcome   string `json:"outcome,omitempty"`
	// LiveStale marks a phase read from a log whose open turn is newer than the
	// liveness answer: Live is false because the answer could not testify about
	// that turn, not because the turn failed. A caller must not render a stale
	// read as an error.
	LiveStale bool `json:"live_stale,omitempty"`
	// Unanswered marks a placeholder snapshot taken while the evidence behind
	// this phase was missing: the status source did not answer (RPC timeout,
	// daemon still starting), the folded log has not caught up, or the write
	// lease could not be observed. Kind stays ErrorKind so every existing
	// consumer keeps its fallback, but a caller that can show "not known yet"
	// must not present this as the session's real state.
	Unanswered bool `json:"unanswered,omitempty"`
}

Snapshot is one session's current phase plus durable facts the caller already needed for display.

func Follow

func Follow(runner, sessionID string, afterSeq int64, tail int) (Snapshot, []dshsessions.TranscriptRow, error)

Follow returns activity plus a committed transcript tail.

func Read

func Read(runner, sessionID string) (Snapshot, error)

Read reports one session's activity using the production probe.

func Wait added in v0.0.247

func Wait(ctx context.Context, runner, sessionID string) (Snapshot, error)

Wait follows a session until its newest turn closes, and answers with the snapshot that closed it.

It is the shared way to "run a turn and see how it ended", which is what a verifier does. The alternative -- each caller writing its own poll loop -- is how a verification grew a ten-minute deadline the main session never had, a status vocabulary of its own, and a stop that could not be told from a timeout. One implementation, so one answer.

The only thing that ends the wait early is ctx: a caller cancelling it means the *user* stopped this turn, and the returned error is ctx.Err() so the caller can say "aborted" rather than inventing an outcome. There is no deadline here on purpose -- a turn runs as long as it runs, exactly as it does for the main session, which no timer interrupts.

func WaitAfter added in v0.0.247

func WaitAfter(ctx context.Context, runner, sessionID string, afterTurns int64) (Snapshot, error)

WaitAfter is Wait, but only accepts a turn that closed *after* the given count of closed turns.

A prompt typed into a session that is momentarily idle leaves a window where the log still describes the previous turn: the turn count has not moved yet. Waiting on that snapshot would answer with the round before the one just asked for. Passing the count observed before handing over the prompt closes the window, and is why this is a comparison rather than a delay.

A negative baseline disables the comparison, for a caller that has no earlier observation.

type WriterSource added in v0.0.238

type WriterSource func(sessionID string) (held bool, known bool)

WriterSource reports whether a live process still holds one session's write lease. Held is the answer; Known says whether the source could answer at all. A process scan can fail, and an unknown lease must never be read as a released one: that would turn an unreadable process table into "every open turn is dead".

Jump to

Keyboard shortcuts

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