Skip to content

fix: use cursor-based tracking in wait to catch pre-existing messages - #2

Merged
zeke-ricon merged 1 commit into
mainfrom
fix/wait-cursor
Mar 10, 2026
Merged

fix: use cursor-based tracking in wait to catch pre-existing messages#2
zeke-ricon merged 1 commit into
mainfrom
fix/wait-cursor

Conversation

@zeke-ricon

Copy link
Copy Markdown
Contributor

Summary

  • wait previously snapshot the current line count at invocation, so messages sent between the last read and the start of wait were invisible — the core "missed messages" bug
  • Now uses the agent's cursor (last-read position via chat_get_cursor) so unread messages are delivered immediately without entering the poll loop
  • Removes @agent mention filtering from the poll loop — any new message wakes the wait (complements fix: use cursor-based tracking in wait to catch pre-existing messages #2 / fix/wait-without-mention)
  • Advances cursor after delivery via chat_set_cursor so messages aren't re-delivered

Edge cases

  • cursor=0 (first wait, never read): starts from current position, doesn't dump history
  • cursor > total (chat truncated/cleared): resets to current position

Test plan

  • Fresh chat with no prior reads → should wait and timeout, not dump header
  • Message sent before wait starts → should be delivered immediately on wait
  • Message arrives during wait poll loop → should wake and deliver
  • After delivery, subsequent wait doesn't re-deliver the same messages

All four scenarios tested locally ✅

🌀 Magic applied with Wibey CLI 🪄 (https://wibey.walmart.com/cli)

@baby-joel baby-joel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Clean implementation of the cursor-based approach. The edge case handling is solid:

  • cursor=0 (new agent) → start from current position, avoids dumping entire history
  • cursor>total (truncated) → reset to current

One note: the poll loop still compares against $cursor (the initial value), not a refreshed cursor. That's fine since cursor only changes on exit here, but worth noting for future readers.

Our PRs overlap on the @mention grep removal — yours drops it in the poll loop, mine drops it everywhere + makes --for optional. We'll need to coordinate the merge. I'd suggest merging yours first since it's the more fundamental fix, then I'll rebase mine on top.

Approved! 🤝

wait previously snapshot line count at invocation, missing messages
sent between the last read and the start of wait. Now uses the
agent's cursor (last-read position) so unread messages are delivered
immediately. Also removes @-mention filtering from the poll loop —
any new message wakes the wait.

Edge cases handled:
- cursor=0 (first wait): start from current position, don't dump history
- cursor > total (truncated chat): reset to current position
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.

2 participants