detached 616eed3

fix(tui): persist transcript to session file after every turn

Previously the tui lazily flushed the agent messages to the
session file only at exit via WriteNewTranscript, plus opt-in via
/session export or /session tree. That meant a mid-session crash,
kill -9, or power loss dropped the entire conversation from disk
even though the summary was visible in the scrollback.

Now the turn-drain goroutine in startTurn() calls FlushSession()
right after i.agent.Prompt returns, while the turn memory is
still hot. FlushSession is the same idempotent helper used by
/session export and /session tree: it appends only the rows past
the current baseline and advances the baseline, so double writes
cant happen even if the exit-time flush also fires.

Ordering in the goroutine: lock -> clear busy/streamOn/cancel ->
read the flush callback -> unlock -> flush -> relock for the
queue-drain and auto-compact decisions. The short unlocked
window is safe because no other goroutine reads those fields at
that moment (busy is already false).

No new config hook; reuses the existing FlushSession the cli
wires in.
commit
616eed3bd63b2b12fdca5d1858c8ffe98a565fea
author
patriceckhart · · 2026-04-20 10:11 UTC
parent
1dafef8
signature
unsigned
refs
tag: v0.0.63
1 file · +12 -0
M internal/agent/modes/interactive.go +12 -0
@@ -2068,6 +2068,18 @@ func (i *Interactive) startTurn(parent context.Context, prompt string) {
20682068 if err != nil && ctx.Err() == nil {
20692069 i.statusErr = err.Error()
20702070 }
2071+ // Persist the assistant's reply (and every tool row before
2072+ // it) to the session file while the turn memory is hot.
2073+ // Without this, WriteNewTranscript only fires at zot exit,
2074+ // meaning a crash or ungraceful kill drops the whole
2075+ // conversation. FlushSession is idempotent (it advances the
2076+ // baseline so subsequent flushes only write new rows).
2077+ flush := i.cfg.FlushSession
2078+ i.mu.Unlock()
2079+ if flush != nil {
2080+ flush()
2081+ }
2082+ i.mu.Lock()
20712083 // Pop the next queued message, if any, and relaunch.
20722084 var next string
20732085 var hasNext bool
@@ -2068,6 +2068,18 @@ func (i *Interactive) startTurn(parent context.Context, prompt string) {
2068 if err != nil && ctx.Err() == nil {2068 if err != nil && ctx.Err() == nil {
2069 i.statusErr = err.Error()2069 i.statusErr = err.Error()
2070 }2070 }
2071+ // Persist the assistant's reply (and every tool row before
2072+ // it) to the session file while the turn memory is hot.
2073+ // Without this, WriteNewTranscript only fires at zot exit,
2074+ // meaning a crash or ungraceful kill drops the whole
2075+ // conversation. FlushSession is idempotent (it advances the
2076+ // baseline so subsequent flushes only write new rows).
2077+ flush := i.cfg.FlushSession
2078+ i.mu.Unlock()
2079+ if flush != nil {
2080+ flush()
2081+ }
2082+ i.mu.Lock()
2071 // Pop the next queued message, if any, and relaunch.2083 // Pop the next queued message, if any, and relaunch.
2072 var next string2084 var next string
2073 var hasNext bool2085 var hasNext bool

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close