ui: the picker holds every row the backend lists

The /sessions rows and the /model rows share one list struct, and the list was
sized with SP_MODEL_CHOICES (96) because /model was its first user. The session
side answers with up to 100 rows (FOREIGN_ROW_MAX in foreignopen.c, the v[100]
in sp_session_list's callers), so the source line said "claude (100)" while the
last four rows were dropped by pick_add without a word. SP_PICK_ROWS (128)
sizes the list on its own.

Evidence: tests/test_ui.sh builds a directory with 100 sessions, filters to the
oldest one and expects its row. With SP_PICK_ROWS 96 the check FAILs
("FAIL shows sess-1795000001-1-1"), with 128 it passes. make check: all tests
passed.
This commit is contained in:
lotherk committed 2026-11-22 23:39:57 +00:00
1 parent 7634c57872
commit cfe0af2688
2 files changed
+38 -3

No files matched your search

+11 -3
View File
@@ -2405,7 +2405,15 @@ draw_prompt(struct ui_state *s, const char *input)
* second copy of the same 120 lines for /sessions would have meant two places
* that handle Esc, resize and the filter differently. What differs is the
* title, the two "nothing here" lines and what Enter does with the choice.
*
* How many rows it holds is not SP_MODEL_CHOICES: that is /model's cap, while
* the session side fills the same struct with up to 100 rows (FOREIGN_ROW_MAX
* and sp_session_list's 100). With the smaller cap the source line said
* "claude (100)" and the last four rows could not be reached - pick_add
* dropped them without a word.
*/
#define SP_PICK_ROWS 128
struct pick_item {
char sel[320]; /* what Enter hands back */
char label[512]; /* what the row shows */
@@ -2413,7 +2421,7 @@ struct pick_item {
};
struct pick_list {
struct pick_item v[SP_MODEL_CHOICES];
struct pick_item v[SP_PICK_ROWS];
size_t n;
};
@@ -2430,7 +2438,7 @@ pick_add(void *ctx, const char *sel, const char *label, int current)
{
struct pick_list *l = ctx;
if (l->n >= SP_MODEL_CHOICES || sel == NULL)
if (l->n >= SP_PICK_ROWS || sel == NULL)
return;
snprintf(l->v[l->n].sel, sizeof(l->v[l->n].sel), "%s", sel);
snprintf(l->v[l->n].label, sizeof(l->v[l->n].label), "%s",
@@ -2609,7 +2617,7 @@ pick_run(struct pick_view *view, struct pick_list *list,
void *pendingctx, char *sel, size_t cap)
{
char filter[64];
size_t flen = 0, match[SP_MODEL_CHOICES], nmatch;
size_t flen = 0, match[SP_PICK_ROWS], nmatch;
size_t cur = 0, top = 0;
WINDOW *win;
int w, h, rc = -1, c;
+27
View File
@@ -278,5 +278,32 @@ sleep 1
check not_shows 'ready. Enter sends' # and PgDn leaves it again
check test "$(quit_code)" = 0
# ---- the picker holds every row the backend lists ----
# The session side can answer with 100 rows (sp_session_list's cap). The picker
# used to size its list with SP_MODEL_CHOICES (96, /model's cap), so a source
# that said "100" had four rows nobody could reach - pick_add dropped them
# silently. 99 files plus this run's own session is exactly 100, and the one
# with the oldest mtime sorts last: it is the row the cap would have cut.
start 4
typed 'single word ok'; key Enter
check shows '<m> ok'
for i in $(seq 1 99); do
printf '{"role":"user","text":"session %s"}\n' "$i" \
> "$D/home/.splinter/sess-17940000$(printf %02d "$i")-1-1.jsonl"
done
printf '{"role":"user","text":"die aelteste zeile"}\n' \
> "$D/home/.splinter/sess-1795000001-1-1.jsonl"
touch -t 202001010000 "$D/home/.splinter/sess-1795000001-1-1.jsonl"
typed '/sessions'; key Enter
check shows 'splinter ('
key Enter
check shows 'Enter opens the session'
# the id is the selector, so filtering by it reaches exactly that row
typed '1795000001'
check shows 'sess-1795000001-1-1'
key Escape; sleep 0.3; key Escape
sleep 0.5
check test "$(quit_code)" = 0
if [ "$fails" -eq 0 ]; then echo "test_ui: ok"; exit 0; fi
exit 1