Help us shape the future of Go! Take the 2026 Go Developer Survey

sessionturn

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sessionturn owns the pre-turn boundary that makes user input durable on disk before a model-provider request is issued.

Index

Constants

This section is empty.

Variables

View Source
var ErrPendingInputMismatch = errors.New("sessionturn: pending retry input does not match the retained user input")

ErrPendingInputMismatch is returned when a retry — a submit made while a prior submit is still pending durability — carries a different input than the retained one. Dispatching it would issue a model request for text that was never made durable, so the retry is rejected without flushing or dispatching

Functions

This section is empty.

Types

type Persister

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

Persister enforces for one session's submit path: it appends the user input as a role:"user" message, makes the session durable via Store.Flush, and only then runs the prepared model-request dispatch. It is stateful so a write failure can be retried without duplicating the retained user message — bind one Persister to one session's store and submit path, and do not share it across sessions.

func New

func New(store *sessions.Store, ui tui.NoticeRenderer) *Persister

New binds a Persister to the active session store and the one-line notice sink used when a write fails. The store and ui are fixed for the session's lifetime; the per-input retry state lives on the returned value.

func (*Persister) PersistUserInputThenIssue

func (p *Persister) PersistUserInputThenIssue(ctx context.Context, input string, imageParts []sessions.ContentPart, dispatch func(submitStart time.Time) error) error

PersistUserInputThenIssue runs the ordering for one user submit: append the user message (first submit only), flush the session to disk, and dispatch the model request only after the flush succeeds.

On a successful flush it clears the retry state and calls dispatch exactly once, returning dispatch's error. On an atomic-write failure (Flush returns a real WriteReason) it routes the failure through the write-failure protocol (sessionfailures.HandleWriteFailure) — appending session_write_failed and rendering the one-line notice — and does NOT dispatch; the retained message stays in memory for a later retry, and the flush error is returned. On a non-atomic flush failure (sessions.ReasonNone: a cancelled context or a marshal error) it returns the flush error without dispatching and without routing through the write-failure protocol, because ReasonNone cannot be encoded as session_write_failed; the message likewise stays retained.

Re-submitting the same retained input after any failure re-flushes the already-appended message rather than appending a duplicate, so durability is retried idempotently. A retry that carries a different input is rejected with ErrPendingInputMismatch — without flushing or dispatching — so the model request can never run for input that was not the one made durable.

dispatch receives the instant the input was accepted (the pre-turn boundary), captured once on the first submit and reused on retries, so the turn it issues can record one end-to-end turn_latency from user submit to final answer.

Jump to

Keyboard shortcuts

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