Repository navigation
Description
Problem
The chat TUI renders differently on every run: spinners animate, elapsed-time strings tick, and the todo box auto-collapses on a wall clock. Two identical runs never produce identical frames, which blocks golden-frame testing and makes captured frames (tmux/PTY) impossible to diff. This is the foundation of the "agent can run → see → fix the TUI" loop; the mock gateway (#817) was step 1 and its side is already deterministic (fixed chatcmpl-mock IDs, call_<step>_<i> tool-call IDs).
Complete list of non-deterministic render inputs (all in internal/ui/components):
- Spinner frames: manual counters stepped from
spinner.TickMsg—conversation_view.go:1303(backgroundSpinStep++),tool_call_renderer.go:203(spinnerStep) time.Now()/time.Sincein render paths:conversation_view.go:1348, :1398, :1421, :1425, :1451, :1455, :1491, :1515, :1523, :1590, :2043;tool_call_renderer.go:112, :144, :145, :151, :193, :202, :278;todo_box_view.go:55, :91;status_view.go:89, :99, :278;task_management_view.go:167, :250;pem_scan.go:118;input_view.go:247, :257 (git-branch cache TTL)- Queued-message wall clock rendered at
conversation_view.go:2559
Design
Env-only switch INFER_TUI_DETERMINISTIC (a dev/test knob — no config field; gateway.mock stays the only user-facing test surface). New internal/ui/components/deterministic.go:
var deterministic = sync.OnceValue(func() bool {
return os.Getenv("INFER_TUI_DETERMINISTIC") != ""
})
var frozenTime = time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
func now() time.Time {
if deterministic() {
return frozenTime
}
return time.Now()
}- Mechanical conversion across the package:
time.Now()→now(),time.Since(x)→now().Sub(x)at the sites listed above. - Three behavioral guards (the only non-mechanical parts):
tool_call_renderer.go:136— a frozen clock makes the update-throttle drop everyToolCallUpdateEventforever; change toif !deterministic() && now().Sub(r.lastUpdate) < constants.ToolCallUpdateThrottle.- Spinner pinning — wrap both manual counters in
if !deterministic(); all glyphs route throughicons.GetSpinnerFrame(step), so step pinned at 0 renders◐always. conversation_view.go:2559— render--:--:--for the queued-message timestamp when deterministic.
- Resulting behavior: elapsed strings collapse to
0s, the todo box never auto-collapses (stays expanded — document it), every frame of a tick loop is identical. Prod path cost: onesync.OnceValueload. - Invariant to state in the
deterministic.godoc comment: a component that renders a timestamp from event data rather thannow()must either receive scripted timestamps in tests or get its own guard —conversation_view.go:2559is the one existing case.
Acceptance criteria
- With
INFER_TUI_DETERMINISTIC=1, two consecutivetmux capture-panesnapshots of an idle-after-response chat are byte-identical - Without the env var, spinners/elapsed strings behave exactly as today
-
task testandtask lintpass
Dependencies
None. Unblocks the golden-frame tests, the PTY e2e test, and the tmux drive-loop packaging (see tracking issue).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity