Skip to content

fix(ui): make prompt history ordering stable and recall just-sent prompts#3059

Open
cak3ninja wants to merge 2 commits into
charmbracelet:mainfrom
cak3ninja:fix/history-order
Open

fix(ui): make prompt history ordering stable and recall just-sent prompts#3059
cak3ninja wants to merge 2 commits into
charmbracelet:mainfrom
cak3ninja:fix/history-order

Conversation

@cak3ninja

@cak3ninja cak3ninja commented Jun 1, 2026

Copy link
Copy Markdown

Fixes #2966

Problem 1 — Prompt history could appear in the wrong order

When several prompts were sent close together, navigating prompt history with ↑/↓ could list them out of order.

Root cause: history was sorted only by the message timestamp, which is stored with one-second granularity. Prompts created within the same second shared an identical timestamp and had no further tiebreaker, so their relative order was undefined.

Fix: sort by insertion order (rowid) as a secondary key in addition to the timestamp. Same-second prompts now keep a deterministic, reverse-send order.

Problem 2 — A just-sent prompt was missing from history

After sending a prompt, pressing ↑ — typically while the agent was still generating a response — would not bring back the prompt you had just sent.

Root cause: history was reloaded at the moment of submitting, in parallel with the message being saved. The reload almost always read the database before the new message was persisted, so it picked up a stale list, and nothing refreshed it afterwards.

Fix: reload prompt history when the user message is actually created (on the message-created event), and remove the racy submit-time reload. The just-sent prompt is now immediately available for recall, even mid-generation.

Tests

  • Unit test covering the navigation/reload behavior after submitting a prompt.

  • Integration test driving the real update loop to verify the message-created event actually triggers the history reload.

  • I have read CONTRIBUTING.md.

  • I have created a discussion that was approved by a maintainer (for new features).

@charmcli

charmcli commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cak3ninja

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@kke

kke commented Jun 8, 2026

Copy link
Copy Markdown

Does this address the problem of messages sent by main agent to sub-agents appear in prompt history?

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.

Up/Down arrow history navigation recalls wrong or stale commands

3 participants