Skip to content

feat: persist TUI sessions#69

Merged
Vasanthdev2004 merged 2 commits into
mainfrom
feat/m3-tui-session-experience
Jun 5, 2026
Merged

feat: persist TUI sessions#69
Vasanthdev2004 merged 2 commits into
mainfrom
feat/m3-tui-session-experience

Conversation

@Vasanthdev2004

@Vasanthdev2004 Vasanthdev2004 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • persist Go TUI sessions with the same event payload contract used by zero exec
  • hydrate /resume <id> and /resume latest into the visible TUI transcript
  • feed resumed session context into the next provider prompt
  • block /resume during active runs and record cancellation markers to avoid corrupt or orphaned session history

Tests

  • go test ./...
  • bun run typecheck
  • bun test ./tests --timeout 15000
  • bun run build

Notes

  • Multi-agent review was used for session API mapping, TUI test patterns, and final review.
  • No MCP/provider transport code touched.

Summary by CodeRabbit

  • New Features

    • Session management to track and persist conversation history and display active session ID
    • /resume command to restore and continue previous sessions (session ID or latest), rebuilding transcripts with past events
    • Capture session events including tool calls, tool results, assistant messages, usage, and errors
  • Bug Fixes / Behavior

    • /resume is blocked while a run is active; cancelling a run records a session error
    • Prompt submission now ensures/creates an active session and records user session events
  • Tests

    • Added comprehensive session/resume test coverage and related test setup changes

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Typecheck: bun run typecheck
  • [pass] Tests: bun run test
  • [pass] Build: bun run build
  • [pass] Smoke build: bun run smoke:build

Scope

Head: 32e66f9555e7
Changed files (5): internal/tui/model.go, internal/tui/model_test.go, internal/tui/session.go, internal/tui/session_controls_test.go, internal/tui/session_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d41cfd37-5ea4-4243-951f-84530f2be48a

📥 Commits

Reviewing files that changed from the base of the PR and between 78e8c50 and 32e66f9.

📒 Files selected for processing (3)
  • internal/tui/model_test.go
  • internal/tui/session.go
  • internal/tui/session_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/tui/model_test.go
  • internal/tui/session.go
  • internal/tui/session_test.go

Walkthrough

This PR adds session state tracking and event persistence to the TUI, enabling transcript reconstruction across multiple agent runs via a /resume command. Session events (messages, tool calls, usage, errors) are accumulated during execution, persisted to a session store, and hydrated when resuming. The /resume command now blocks while a run is active and injects prior session context into resumed prompts.

Changes

Session state tracking and resume flow

Layer / File(s) Summary
Session state data structures
internal/tui/model.go
Model gains activeSession metadata and sessionEvents slice; agentResponseMsg adds sessionEvents to carry accumulated session events from agent runs.
Session lifecycle and event persistence helpers
internal/tui/session.go
New module implementing session creation (ensureActiveSession), event persistence (appendSessionEvent, appendSessionEvents), resume command handling (handleResumeCommand), prompt transformation (sessionPrompt), session resolution (resolveResumeSession), and transcript reconstruction from persisted events (transcriptRowsFromSessionEvents, sessionPayload, payloadString).
Resume and prompt submission command handling
internal/tui/model.go
/resume command blocks while run is active; otherwise hydrates transcript and restores session context. Prompt submission ensures active session exists, records user event, and transforms prompt before sending to agent.
Agent execution with session event accumulation
internal/tui/model.go
runAgent initializes pending session events and enqueues tool call/result/usage events via callbacks; on error or success, enqueues corresponding session events. cancelRun records session cancellation error.
Model update and UI display
internal/tui/model.go
Update handler processes agentResponseMsg.sessionEvents to append transcript rows; contextText() displays active session ID.
Test infrastructure and comprehensive test suite
internal/tui/model_test.go, internal/tui/session_controls_test.go, internal/tui/session_test.go
Existing tests updated to include SessionStore. New test file introduces scripted provider test double and validates session event persistence, transcript hydration on resume, command blocking during runs, cancellation error recording, context injection into resumed prompts, and missing-session error handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Gitlawb/zero#66: Related TUI changes around usage/footer/context and command handling that interact with persisted session events.
  • Gitlawb/zero#63: Prior TUI command wiring and resume-related refactors that this PR builds upon.

Suggested reviewers

  • gnanam1990
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: persist TUI sessions' directly and concisely describes the main change: adding session persistence to the TUI, which is the primary objective of this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/m3-tui-session-experience

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tui/session_test.go`:
- Line 164: The test contains an ineffectual assignment to updated from
next.Update(cmd()) that is never used; replace the assignment with the blank
identifier so the return values are ignored (e.g. use "_, _ =
next.Update(cmd())" or otherwise handle the error) for the call in
session_test.go (reference: updated, next.Update, cmd()); apply the same change
to the other occurrence noted around line 354.

In `@internal/tui/session.go`:
- Line 133: Change the capitalized, punctuated error strings to idiomatic Go by
lowercasing the first letter and removing the trailing period in the errors.New
calls; specifically replace errors.New("No Zero sessions available to resume.")
(and the similar errors.New(...) at the other occurrence around line 143) with
errors.New("no zero sessions available to resume") in internal/tui/session.go so
both returned errors follow ST1005 style.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 22be84f2-a792-4e26-bd19-707d41f7df12

📥 Commits

Reviewing files that changed from the base of the PR and between a09a721 and 78e8c50.

📒 Files selected for processing (5)
  • internal/tui/model.go
  • internal/tui/model_test.go
  • internal/tui/session.go
  • internal/tui/session_controls_test.go
  • internal/tui/session_test.go

Comment thread internal/tui/session_test.go Outdated
Comment thread internal/tui/session.go Outdated

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this slice is structurally solid and the local verification passed for me:

  • go test -count=1 ./internal/tui
  • go test -count=1 ./internal/sessions ./internal/tui
  • go test -count=1 -p 1 ./...

Requesting changes only for the two current CodeRabbit findings, which I verified are still valid on 78e8c50:

  • internal/tui/session_test.go: replace the two unused updated, _ = next.Update(cmd()) assignments with ignored return values or consume the returned model.
  • internal/tui/session.go: normalize the returned error strings to idiomatic Go style by lowercasing and removing trailing punctuation.

No additional blockers found from my local review.

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the updated head 32e66f9.

The previously requested fixes are in place:

  • the two unused next.Update(cmd()) assignments now ignore returned values
  • resume errors now use idiomatic lowercase/no-period Go strings

Local validation passed:

  • go test -count=1 ./internal/tui
  • go test -count=1 -p 1 ./...

No further blockers from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants