fix(inbox): mark only the displayed messages as read#361
Open
ryofukutani wants to merge 1 commit into
Open
Conversation
inbox.sh and check-inbox.sh selected the unread messages, displayed them, then marked as read with a blanket `UPDATE ... WHERE team=... AND to_agent=... AND read_at IS NULL`. The WHERE clause is re-evaluated at UPDATE time, so a message that arrives between the SELECT and the UPDATE is marked read without ever having been displayed — it silently disappears from every future inbox check. Carry the message ids through the display loop and mark exactly those ids (`WHERE id IN (...)`), so a late-arriving message stays unread and surfaces on the next check. Ids are validated numeric before splicing into SQL. Adds tests/test_inbox.bats: basic display/mark and --quiet pins, plus a deterministic race regression test for both scripts using a small two-file barrier seam (AGMSG_TEST_MARK_BARRIER, no-op unless set; 10s safety cap). The race test fails against the old blanket UPDATE (verified by mutation) and passes 5/5 against the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
inbox.sh/check-inbox.shselect the unread messages, display them, then mark as read with a blanketUPDATE … WHERE team=… AND to_agent=… AND read_at IS NULL. The WHERE clause is re-evaluated at UPDATE time, so a message that arrives between the SELECT and the UPDATE is marked read without ever having been displayed — it silently disappears from every future inbox check.We hit this in production-style multi-lane use (several agents + watchers on one machine): a reply landing while a turn-hook check was mid-flight was swallowed unseen.
Fix
Carry the message ids through the display loop and mark exactly those ids (
WHERE id IN (…)). A late-arriving message stays unread and surfaces on the next check. Ids are validated numeric before being spliced into SQL (mirrors the #87 hardening posture).Tests
New
tests/test_inbox.bats(the first coverage for these two scripts):--quietbehavior pinsAGMSG_TEST_MARK_BARRIER, no-op unless set, 10s safety cap) — the test lands a message inside the display→mark window and asserts it is not marked read unseentest_delivery125/125,test_codex_bridge27/27,test_messaging,test_storage,test_watch_once,test_dispatch,test_team,test_installIf you'd prefer a different seam mechanism (or none), happy to adjust — the id-based marking stands on its own.