fix: restore mailbox on consume_pending session write failure - #1161
Open
STiFLeR7 wants to merge 1 commit into
Open
fix: restore mailbox on consume_pending session write failure#1161STiFLeR7 wants to merge 1 commit into
STiFLeR7 wants to merge 1 commit into
Conversation
consume_pending() drains the agent's mailbox and zeroes pending_counts under the lock, then - outside the lock - tries to persist the drained items via session.add_items(). On failure it only logged the exception and fell through to returning the original (now-inflated) count as if the write had succeeded. Callers with include_items=False (execution.py after a wait, respond/tool.py) rely entirely on the session for the next turn, so a transient write failure (e.g. a locked SQLite session) silently dropped the user's message: not in the mailbox (already cleared), not in the session (write failed), and reported as delivered to the caller. On write failure, restore the drained messages to the front of the mailbox and add their count back to pending_counts, wake the runtime so a blocked wait_for_message() notices the pending work again, and return (0, []) so this attempt is honestly reported as not having delivered anything. This makes the next consume_pending() call retry the same messages instead of losing them. Fixes usestrix#1107.
Contributor
Greptile SummaryRestores drained mailbox messages when session persistence fails so they can be retried instead of silently lost.
Confidence Score: 5/5The PR appears safe to merge, with the restored mailbox state remaining reachable by the existing pending-message retry flow. The failure path restores the original batch ahead of concurrent arrivals under the coordinator lock, repairs pending-count state, and causes the next wait cycle to retry delivery; no blocking or independently actionable issue remains. Important Files Changed
Reviews (1): Last reviewed commit: "fix: restore mailbox on consume_pending ..." | Re-trigger Greptile |
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.
Summary
consume_pending()drains the agent's mailbox and zeroespending_countsunder the lock, then — outside the lock — tries to persist the drained items viasession.add_items(). On failure it only logged the exception and fell through to returning the original (now-inflated)countas if the write had succeeded.Callers with
include_items=False(execution.pyafter a wait,respond/tool.py) rely entirely on the session for the next turn — they don't get the items back, just a count. So a transient write failure (e.g. a locked SQLite session) silently dropped the user's message: not in the mailbox (already cleared), not in the session (write failed), and reported as delivered to the caller.Fix
On write failure:
pending_counts.runtime.wakeso a blockedwait_for_message()notices the restored pending work.(0, [])so this attempt is honestly reported as not having delivered anything.This makes the next
consume_pending()call retry the same messages instead of losing them, matching the issue's suggested fix.Fixes #1107.
Testing
test_consume_pending_restores_mailbox_on_session_write_failure, which injects a failingsession.add_itemsviamonkeypatch, asserts the mailbox/pending_countsare restored and(0, [])is returned, then removes the failure and confirms a subsequentconsume_pending()call successfully delivers the same message.count=1returned despite the write failing); restored the fix, confirmed it passes.uv run pytest tests/test_execution.py -q: 60 passed.uv run pytest tests/ -q: 1062 passed; 21 pre-existing failures confirmed present on unmodifiedmaintoo (all Windows-specific — POSIX permission-bit assertions and a path-parsing bug that misreads a Windows drive letter as a path segment), none related toagents.pyor this change.uv run ruff check,uv run ruff format,uv run mypy strix/core/agents.py: all clean.