Skip to content

fix(agent): keep queued inputs in native order when switching queues - #25

Closed
rajnishmanitiwari wants to merge 1 commit into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/queue-input-order
Closed

rajnishmanitiwari wants to merge 1 commit into
w01fb0ss:mainfrom
rajnishmanitiwari:fix/queue-input-order

Conversation

@rajnishmanitiwari

Copy link
Copy Markdown

Fixes #20.

requeue() rebuilt each queue from the tracked Map, so switching one queued input reordered the others into Map insertion order. Each queue is now restored in the order clearQueue returned it: tracked entries keep their native slots (with images), unmatched entries stay where they were, and the switched input joins its new queue last. An input pi already took is still dropped and still reports false.

Tests: new packages/agent/test/session-additions.test.ts, 3 tests, all pass; the two order tests fail without the fix (sensitivity checked); full @pibot/agent suite 66/66 pass; package typecheck clean; Biome check clean on both touched files.

requeue() rebuilt each queue from the tracked Map, so switching one
queued input reordered the others into Map insertion order. Each queue
is now restored in the order clearQueue returned it: tracked entries
keep their native slots (with images), unmatched entries stay where
they were, and the switched input joins its new queue last. An input
pi already took is still dropped and still reports false.

Fixes w01fb0ss#20.

Signed-off-by: Rajnish Mani Tiwari <76885104+rajnishmanitiwari@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 09:04

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@w01fb0ss

Copy link
Copy Markdown
Owner

Thanks for the fix and the tests — rebuilding each queue from clearQueue()'s native order is a cleaner approach than what's there now.

One case it still misses: two queued inputs with the same text (e.g. "continue" sent twice). findIndex matches by text, and a slot that already holds a tracked input still has the same .text, so the second input lands on the first one's slot — its own slot stays a bare { text } (images lost) and the order can shift. Could you claim each slot only once (e.g. skip indices already assigned, or match duplicates first-in-first-out) and add a test with two identical texts, one carrying images?

Heads-up: #21 by @agooll targets the same issue (#20) and is waiting on a similar change. We'll merge whichever lands a complete fix first, and credit both of you in the release notes.

@w01fb0ss

w01fb0ss commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Thanks a lot for working on this, and for the tests. #21 fixes the same queue-switching bug and now also covers the duplicate-text case, and its checks pass, so I'm closing this one in favour of it. #21 had already taken the same approach — rebuilding the queues from clearQueue()'s native order — which you reached independently, and I've added a thank-you to you in the README. Contributions are very welcome; feel free to pick up anything else that catches your eye.

@w01fb0ss w01fb0ss closed this Nov 26, 2026
w01fb0ss added a commit that referenced this pull request Nov 26, 2026
Signed-off-by: leen.zhou <leen.zhou.cn@gmail.com>
w01fb0ss added a commit that referenced this pull request Nov 26, 2026
Signed-off-by: leen.zhou <leen.zhou.cn@gmail.com>
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.

Switching a queued input can reorder other messages in the Pi session

3 participants