Repository navigation
fix(asks): a capped read of pending asks keeps the longest-waiting ones (#3679) - #3809
Merged
Merged
Conversation
…es (#3679) list_items ordered every row by sort_time descending inside its priority, so pending asks came newest first; the Workspace Inbox and the operator queue each read one capped page (200) and show it oldest first, so past the cap the asks that had waited longest were never shown. Pending rows now sort oldest first; ended rows keep their newest-ended-first order (#627 AC6). The two age keys are NULL across each other's group, so NULL placement never decides an order on SQLite or PostgreSQL. The Workspace footer's '200 most recent asks' note now says what the page holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#3679) The fixture proves the addressee filter runs in SQL by building a page that crowds the client's ask out without it. It relied on newest-first ordering; with pending oldest first, the client's ask is now raised after the noise. On the old ordering its own precondition trips, so it also guards #3679. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
db/operator_queue.py::list_itemsordered every row bysort_timedescending within its priority, so pending asks came newest first. The Workspace Inbox and the operator queue each read one capped page of 200 and then show it oldest first. Once more asks were pending than the cap, the page they received had already dropped the asks that had waited longest, and neither client could show them.The fix (one ORDER BY):
created_atascending) after priority, so the cap drops the newest.status_orderalready separates the groups, so NULL placement never decides an order. SQLite and PostgreSQL put NULLs at opposite ends, which is why this matters.The Workspace's capped-read footer said "Showing your 200 most recent asks", which would now be wrong. It reads "Showing your first 200 asks: the ones waiting longest come first." The spec and
feature-flows/workspace-inbox.mdare updated to match.Not changed: the ent#815 cursor walk (
_walk_query). A walk visits every page, so no ask is cut, and its cursor predicate encodes the direction.Fixes #3679
Tests
tests/unit/test_3679_pending_asks_oldest_first.pyruns on real SQLite with ages set explicitly. Ondev, 3 of its 4 cases fail; the priority case already passed. It checks:portalInbox.mount.spec.js+portalInbox.spec.js: 203 passed.test_ent428_workspace_asks.py::test_a_busy_fleet_does_not_crowd_out_one_client_askis updated. Its fixture proves the addressee filter runs in SQL by building a page that crowds the client's ask out without the filter, and it relied on newest-first ordering. The client's ask is now raised after the noise. On the old ordering the fixture's own precondition trips, so this test also guards bug: a capped read of pending asks drops the longest-waiting ones (server sorts newest first, clients show oldest first) #3679. 26/26 pass.devcode and are not touched by this change:test_ent751_gate_callers(the same file as flaky Flaky: test_ent751_gate_callers TestPortal held-turn notice is not persisted ~1 in 8 runs (order-dependent) #3691);test_ent679_a2a_payment_gate(KeyError: 'result').GET /api/operator-queue?status=pending&limit=3returned asks 5, 4, 3. The older ones were dropped.Not run locally: the PostgreSQL track. The ORDER BY uses only
CASEandASC/DESC, both portable, and the NULL halves never meet across groups.🤖 Generated with Claude Code