Repository navigation
TUI: stop sort-drift on navigation + load newest session on launch - #184
Conversation
Two user-reported bugs against PR #182's newest-first session sort, both in the TUI start/navigate path: Bug A -- sort drift when picking older sessions SelectSession used to call PersistSession on the outgoing session "to flush anything pending before the swap." But by the time you get there, every meaningful state change has already been persisted: PollLoopWorker's ApplyLoopResultTo saves after each turn, ApplyModelSelection saves after /model, and so on. Pure navigation had nothing to save -- but PersistSession's unconditional FSession.Touch bumped Meta.UpdatedAt anyway, so peeking at an older session re-promoted the one you LEFT to the top of the newest-first list. Dropped the Persist call. Added a comment explaining what's already persisted at each entry point so a future hand doesn't re-add it on the theory it might miss something. Bug B -- TUI launches with empty chat, mismatched highlight With no --session argument, the left pane highlighted the newest session but the chat pane was blank. TSession.Create('') auto- allocates a brand-new session id, so FSession pointed at a fresh empty in-memory record while FSelSessIdx tracked the newest persisted session at index 0. SessionId resolution in TTUI.Run now does: empty + sessions on disk -> resume the newest by UpdatedAt; empty + no sessions on disk -> fresh id (original PR #117 behavior); non-empty -> honour as-is. Pressing N still spawns a fresh session via StartNewSession -> SelectSession('').
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23f4d4a3c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { Persist anything pending on the current session before swapping. } | ||
| if (FSession <> nil) and (Length(FSession.Messages) > 0) then | ||
| PersistSession; | ||
| FSession.Free; |
There was a problem hiding this comment.
Preserve in-flight prompts before swapping sessions
When the user submits a prompt and then opens another session before the loop finishes, StartTurn has only appended the user message to the in-memory FSession.Messages; it is not saved until the loop succeeds. After this change frees that object without persisting it, the timeout/failure paths call AppendErrorTo for FLoopSessionId, which reloads the original session from disk because the current session is different, so the saved transcript contains only the error and loses the prompt that triggered it. This also affects quitting after navigating away while the request is still pending. Avoid touching UpdatedAt for pure navigation, but keep a targeted save for an in-flight unsaved user turn before discarding the session object.
Useful? React with 👍 / 👎.
Codex P2 -- Preserve in-flight prompts before swapping sessions. The previous fix dropped PersistSession from SelectSession to stop pure navigation from bumping UpdatedAt. But it ALSO dropped the persist in a case where the persist actually mattered: when a tool loop is in flight on the outgoing session, StartTurn has appended the user's prompt to in-memory FSession.Messages but not to disk yet. If the user navigates away and the loop later times out or fails, PollLoopWorker's AppendErrorTo reloads the session by id, sees only the disk state (no prompt), appends the error, saves -- so the persisted transcript contains the error with no record of the prompt that triggered it. Fix: gate the PersistSession on (FLoopThread <> nil) AND (FLoopSessionId = FSession.Meta.Id). Pure navigation still doesn't Touch; in-flight navigation does (and the UpdatedAt bump is correct in that case -- there IS new content). Tab overflow -- "1-2 chars bleed to next line" on long markdown content. VisibleLength counts a tab as 1 column, but the terminal expands it to the next 8-column tab stop (1-7 extra columns depending on the cursor's current column). Markdown code blocks from the model frequently include tab-indented content, so the wrap math was undercounting visible width and the line ran past the chat pane's right edge -- the terminal wrapped to col 0 of the next physical row. Fix: replace tabs with 4 spaces in the rendered body before the wrap pass. Space-indented content passes through unchanged; tab- indented content widens slightly but stays within the pane.
Summary
Two user-reported regressions against PR #182's newest-first session sort. Both live in the TUI session start/navigate path.
Bug A — sort drifts when picking older sessions
Symptom: open
pasclaw tui, peek at an older session from the left pane, come back — and the order has reshuffled. The session you just left is now at the top.Root cause:
SelectSessioncalledPersistSessionon the outgoing session "to flush anything pending before the swap." By the time we reachSelectSession, every meaningful state change is already on disk —PollLoopWorker.ApplyLoopResultTosaves after each turn,ApplyModelSelectionsaves after/model, etc. Pure navigation had nothing to save — butPersistSession's unconditionalFSession.TouchbumpedMeta.UpdatedAtanyway, so the nextRefreshSessionsre-sorted the just-departed session to the top.Fix: drop the Persist call in
SelectSession. Added a comment listing what's already persisted at each entry point so a future maintainer doesn't re-add it on the theory it might miss something.Bug B — TUI launches with empty chat, mismatched highlight
Symptom:
pasclaw tuiwith no args shows the newest session highlighted in the left pane, but the chat pane is empty.Root cause: when
SessionIdis empty,TSession.Create('')auto-allocates a brand-new session id and returns an in-memory blank —FSession.Meta.Iddoesn't match any persisted session.RefreshSessionsthen can't find it inFSessionsand falls back toFSelSessIdx := 0, which highlights the newest persisted session. So the highlight and the rendered chat diverge.Fix: in
TTUI.Run, resolveSessionIdbefore creating the session:--session id): honor as-is (existing behavior — pre-seed if missing, resume if present).UpdatedAt—pasclaw tuipicks up where you left off, highlight matches chat.Nstill spawns a fresh session viaStartNewSession → SelectSession('')— that path is unchanged.Test plan
makerebuilds cleanlymake test— all 13 suites greenpasclaw tuiagainst a workspace with several sessions — confirm the newest session loads in the chat pane, with its row highlighted in the left pane.pasclaw tui --session <existing-id>— confirm the explicit id still wins.pasclaw tuiagainst an empty workspace (nosessions/*.json) — confirm a fresh session is allocated, persists on first turn.Generated by Claude Code