Skip to content

Commit 24addab

Browse files
committed
fix(cli-rs): toast a failed transcript read with its message alone
When message.list fails as a session opens, TS's createSessionRows drops the error and the session opens with an empty transcript. prependHistory drops an older page's failure the same way. In both cases the user gets no sign that the transcript did not load. Under O-89 Rust keeps its toast for these failures and records the difference in O89-transcript-read-toast. These toasts, and the session.first toast that TS also shows, used the error's Display, which puts the tag in front. They now show the message alone, as toast.error does. P-APP E.6a/history-failed drives the deviation: TS's empty transcript, and Rust's equal cells apart from the toast's box. A navigate row covers the session open, page up, the previous-message walk and session.first.
1 parent a5750d6 commit 24addab

8 files changed

Lines changed: 194 additions & 19 deletions

File tree

‎packages/cli-rs/crates/tui/src/routes/session/messages/list.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,15 @@ impl Transcript {
468468
}
469469

470470
/// Loads every older page in one publication (`session.first`). The window stays until `done`
471-
/// mounts the head.
471+
/// mounts the head; a failure reaches it as the error's message alone (`toast.error`).
472472
pub fn load_all(&self, tui: &Tui, done: impl FnOnce(&Tui, Result<(), String>) + 'static) {
473473
let Some(session) = self.session() else { return };
474474
let data = tui.data.clone();
475475
tui.app.spawn(
476476
async move { data.message_load_more(&session, LoadMore { all: true, ..LoadMore::default() }).await },
477477
bind!(self.0.this, |inner, _, result| {
478478
let Some(tui) = inner.tui.upgrade() else { return };
479-
done(&tui, result.map_err(|error| error.to_string()));
479+
done(&tui, result.map_err(|error| error.tui_message()));
480480
}),
481481
);
482482
}
@@ -1024,7 +1024,8 @@ impl Inner {
10241024
self.render(tui, |_| false);
10251025
}
10261026

1027-
/// `prependHistory`: loads the next older page; the store's flush mounts it.
1027+
/// `prependHistory`: loads the next older page; the store's flush mounts it. A failure shows a toast, where TS
1028+
/// shows nothing (deviation `O89-transcript-read-toast`).
10281029
fn load_older(&self, tui: &Tui) -> bool {
10291030
let Some(session) = self.session.borrow().clone() else { return false };
10301031
if self.loading.get() || !tui.data.read(|state| state.has_more_messages(&session)) {
@@ -1042,7 +1043,7 @@ impl Inner {
10421043
let Some(tui) = inner.tui.upgrade() else { return };
10431044
match result {
10441045
Ok(_) => inner.complete_group_boundary(&tui),
1045-
Err(error) => tui.toasts.error(error.to_string()),
1046+
Err(error) => tui.toasts.error(error.tui_message()),
10461047
}
10471048
}),
10481049
);

‎packages/cli-rs/crates/tui/src/routes/session/mod.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,17 @@ fn composer_slot(tui: &Tui, parent: &View, id: &SessionID) -> opencode_plugin::S
215215
)
216216
}
217217

218-
/// Awaits a store read; a failure shows as an error toast.
219-
pub(super) fn load(tui: &Tui, task: Task<()>) {
220-
tui.request(task, |_, ()| {});
218+
/// Awaits the transcript's first read; a failure shows the error's message as a toast, where TS shows nothing
219+
/// (deviation `O89-transcript-read-toast`).
220+
fn load(tui: &Tui, task: Task<()>) {
221+
tui.app.spawn(
222+
task,
223+
opencode_ui::bind!(tui, |tui, _, result| {
224+
if let Err(error) = result {
225+
tui.toasts.error(error.tui_message());
226+
}
227+
}),
228+
);
221229
}
222230

223231
/// Once the page lands, compiles the grammars its code fences name on workers while the UI builds the rows, so the

‎packages/cli-rs/crates/tui/src/routes/session/navigation.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ impl Inner {
103103
let Some(tui) = inner.tui.upgrade() else { return };
104104
match result {
105105
Ok(()) => after_layout(&tui.app.clone(), move || inner.to_message(&tui, next, user_only)),
106-
Err(error) => tui.toasts.error(error.to_string()),
106+
// TS's `prependHistory` drops it (deviation `O89-transcript-read-toast`).
107+
Err(error) => tui.toasts.error(error.tui_message()),
107108
}
108109
}),
109110
);

‎packages/cli-rs/crates/tui/tests/all/navigate.rs‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ use crate::support::{self, Fake, Harness, WAIT, deref_harness};
44

55
use std::rc::Rc;
66
use std::sync::Arc;
7-
use std::sync::atomic::{AtomicUsize, Ordering};
7+
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
88
use std::time::Duration;
99

1010
use opencode_local::cli_config::{Info, Session, Verbosity};
1111
use opencode_tui::{Deps, Route};
1212
use serde_json::{Value, json};
1313

1414
/// Serves the same messages for every session, newest page first, `limit` at a time, with a cursor that
15-
/// counts the messages older than the page; `older` counts the reads of an older page.
16-
fn fake(messages: Vec<Value>, older: Arc<AtomicUsize>) -> Fake {
15+
/// counts the messages older than the page; `older` counts the reads of an older page. While `failing` is set, every
16+
/// message read fails.
17+
fn fake(messages: Vec<Value>, older: Arc<AtomicUsize>, failing: Arc<AtomicBool>) -> Fake {
1718
Fake::new(move |seen| {
1819
let path = seen.path.as_str();
1920
let id = path.strip_prefix("/api/session/").and_then(|rest| rest.split('/').next()).unwrap_or_default();
@@ -25,12 +26,13 @@ fn fake(messages: Vec<Value>, older: Arc<AtomicUsize>) -> Fake {
2526
let limit = seen.param("limit");
2627
let limit: usize = if limit.is_empty() { 20 } else { limit.parse().unwrap() };
2728
let cursor = seen.param("cursor");
28-
let end = if cursor.is_empty() {
29-
messages.len()
30-
} else {
29+
if !cursor.is_empty() {
3130
older.fetch_add(1, Ordering::SeqCst);
32-
cursor.parse().unwrap()
33-
};
31+
}
32+
if failing.load(Ordering::SeqCst) {
33+
return (500, json!({ "_tag": "UnknownError", "message": "the read failed", "ref": "err_1" }));
34+
}
35+
let end = if cursor.is_empty() { messages.len() } else { cursor.parse().unwrap() };
3436
let start = end.saturating_sub(limit);
3537
let page: Vec<_> = messages[start..end].iter().rev().cloned().collect();
3638
let next = (start > 0).then(|| start.to_string());
@@ -92,19 +94,21 @@ fn turns(count: u64) -> Vec<Value> {
9294
struct Nav {
9395
harness: Harness,
9496
older: Arc<AtomicUsize>,
97+
failing: Arc<AtomicBool>,
9598
}
9699

97100
deref_harness!(Nav);
98101

99102
fn open(messages: Vec<Value>, info: Info) -> Nav {
100103
let last = messages.len() / 2;
101104
let older = Arc::new(AtomicUsize::new(0));
102-
let fake = fake(messages, older.clone());
105+
let failing = Arc::new(AtomicBool::new(false));
106+
let fake = fake(messages, older.clone(), failing.clone());
103107
let deps =
104108
Deps { config: support::config(info), route: support::session_route("ses_n"), ..support::deps(Arc::new(fake)) };
105109
// The transcript keeps the 15-row view these cases were written for (E.12 took the session header and
106110
// the column gaps out, so it grew by five rows at 80x30).
107-
let h = Nav { harness: support::mount(80, 25, deps), older };
111+
let h = Nav { harness: support::mount(80, 25, deps), older, failing };
108112
h.wait_for(&format!("Answer {last} three."));
109113
h
110114
}
@@ -310,6 +314,29 @@ fn message_navigation_aligns_messages_with_the_top() {
310314
assert_eq!(Nav::row(&screen, "Question 1"), Some(TOP + 1), "{screen}");
311315
}
312316

317+
/// A failed transcript read shows the error's message alone as a toast, without its tag: a session's first page, and
318+
/// an older page whichever move asked for it (deviation `O89-transcript-read-toast` for all but `session.first`, which
319+
/// toasts in TS too).
320+
#[test]
321+
fn a_failed_transcript_read_toasts_its_message() {
322+
for command in ["session open", "session.page.up", "session.message.user.previous", "session.first"] {
323+
let h = open(turns(30), Info::default());
324+
h.failing.store(true, Ordering::SeqCst);
325+
if command == "session open" {
326+
h.tui.navigate(support::session_route("ses_m"));
327+
h.app.advance(Duration::from_millis(1));
328+
}
329+
for _ in 0..400 {
330+
if command == "session open" || h.older.load(Ordering::SeqCst) > 0 {
331+
break;
332+
}
333+
h.dispatch(command);
334+
}
335+
let screen = h.wait_for("the read failed");
336+
assert!(!screen.contains("UnknownError"), "{command}:\n{screen}");
337+
}
338+
}
339+
313340
#[test]
314341
fn groups_open_on_click_and_follow_grouping_and_verbosity() {
315342
// Low, the default, folds a turn's calls into one activity summary.
@@ -485,7 +512,7 @@ fn home_and_end_navigate_a_subagent_transcript() {
485512
route: support::session_route("ses_sub"),
486513
..support::deps(Arc::new(fake))
487514
};
488-
let h = Nav { harness: support::mount(100, 30, deps), older: Arc::default() };
515+
let h = Nav { harness: support::mount(100, 30, deps), older: Arc::default(), failing: Arc::default() };
489516
let screen = h.wait_for("Message 19");
490517
assert!(screen.contains("Subagents"), "{screen}");
491518
assert!(!screen.contains("Message 0\n") && !screen.contains("Message 0 "), "{screen}");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# O89: a failed transcript read shows a toast
2+
3+
**TypeScript.** When the first `message.list` of a session fails, `data.session.message.sync` rethrows
4+
(`packages/client/src/solid/data.ts:1880-1922`), and `createSessionRows` drops the error with `.catch(() => undefined)`
5+
(`packages/tui/src/routes/session/rows.ts:128-143`). The session opens with an empty transcript, as if it had no
6+
messages. Nothing is shown or logged, and nothing reads the page again until the session or the connection status
7+
changes. A failed older page is dropped in the same way. `loadMore` rethrows (`data.ts:1924-1987`), and
8+
`createHistoryPrepend` handles the rejection by clearing its pending load and running nothing else
9+
(`packages/tui/src/routes/session/history.ts:25-42`). This applies to a scroll near the top and to the
10+
previous-message walk (`routes/session/index.tsx:884`). The older messages never arrive, and nothing says why. Only
11+
`session.first` shows its failure (`toast.error(error)`, `index.tsx:1035`).
12+
13+
**Rust.** The same failures show an error toast with the error's message alone, as `toast.error` shows it: the
14+
session's first read (`routes/session/mod.rs` `load`), an older page (`messages/list.rs` `load_older`) and the
15+
previous-message walk (`navigation.rs`). Everything else matches TS. The transcript keeps what it had, the scroll
16+
position is not restored after a failed first read, and Rust adds no retry: a later scroll near the top, or another
17+
previous-message move, asks again as it does in TS. P-APP `E.6a/history-failed` records this. The cells outside the
18+
toast equal TS's empty transcript.
19+
20+
**Reason.** The user's decision O-89: fix in Rust the defects TS shares, and record them as deviations. Without the
21+
toast, the user has no sign that the transcript failed to load.

‎packages/cli-rs/parity/fixtures/E.6a/history-failed.app.json‎

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)