Skip to content

[FEATURE] Deterministic TUI render mode via INFER_TUI_DETERMINISTIC #823

Closed as not planned

Description

@edenreich

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.Since in 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):
    1. tool_call_renderer.go:136 — a frozen clock makes the update-throttle drop every ToolCallUpdateEvent forever; change to if !deterministic() && now().Sub(r.lastUpdate) < constants.ToolCallUpdateThrottle.
    2. Spinner pinning — wrap both manual counters in if !deterministic(); all glyphs route through icons.GetSpinnerFrame(step), so step pinned at 0 renders ◐ always.
    3. 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: one sync.OnceValue load.
  • Invariant to state in the deterministic.go doc comment: a component that renders a timestamp from event data rather than now() must either receive scripted timestamps in tests or get its own guard — conversation_view.go:2559 is the one existing case.

Acceptance criteria

  • With INFER_TUI_DETERMINISTIC=1, two consecutive tmux capture-pane snapshots of an idle-after-response chat are byte-identical
  • Without the env var, spinners/elapsed strings behave exactly as today
  • task test and task lint pass

Dependencies

None. Unblocks the golden-frame tests, the PTY e2e test, and the tmux drive-loop packaging (see tracking issue).

Activity

  1. added
    enhancement
    on Jul 10, 2026
  2. moved this to Todo in 2026on Jul 10, 2026
  3. moved this from Todo to Done in 2026on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions