Repository navigation
fix(agent): preserve delivery order when switching queued input - #21
Conversation
Rebuild the native queues in their SDK order, keeping tracked images and appending only the moved item at the end of its new queue. Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
w01fb0ss
left a comment
There was a problem hiding this comment.
Thanks for this, and for the precise steps in #20. Replaying each queue in the order the SDK returns it is a nice simplification, and keeping attachments on matched inputs is good. One small request: keying tracked by ${mode}:${text} collapses inputs with identical text in the same queue (the last one wins). Today append refuses duplicate pending text, so it can't happen yet, but if that guard ever relaxes, moving the first of two identical inputs would return false and re-add one of them without its images. The old indexOf/splice paired them one-to-one. Could you keep a list per key and shift() from it (sketch below), and update the requeue doc comment to say the moved input now joins the end of its destination queue? With that I'm happy to merge. Thanks again!
const tracked = new Map<string, { key: string; input: Input }[]>();
for (const [key, input] of additions.queued) {
const lookup = `${input.mode}:${input.text}`;
tracked.set(lookup, [...(tracked.get(lookup) ?? []), { key, input }]);
}
// in the loop:
const match = tracked.get(`${queue}:${text}`)?.shift();Consume tracked matches once per native queue slot so switching the first duplicate preserves the images of both inputs. Document destination tail insertion and cover it in the regression test. Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
|
Thanks for the follow-up — c5051fb handles the duplicate-text case exactly as it should: each |
Signed-off-by: leen.zhou <leen.zhou.cn@gmail.com>
What and why
Fixes #20. Switching a pending input between
steerandfollowUpclears and rebuilds the Pi SDK queues. Restoring untracked entries first and tracked entries in Map insertion order changes the order of inputs that were supposed to stay put.Replay each queue in the order returned by the SDK and append the moved input to the destination queue. Preserve attachments on matched tracked inputs and skip tracked entries the SDK already consumed.
Checks
pnpm verifypasses locally.envfiles or local pathsThe regression fails on upstream
5a4f5f9and passes with the patch. It checks both queues, the moved input's image attachment and mode, and that an already-consumed input is not reinserted. The Agent Vitest project passed all 64 tests. Biome andgit diff --checkpassed.