Merge PR #7: cart improvements, search_batch, cart_diff, price sanity checks#13
Merged
Conversation
Session analysis revealed the model burned 74 minutes debugging issues that better tool feedback would have prevented. This commit addresses the top 9 improvements from that analysis: A. Cart returns total_units (sum of qty) alongside items_count (unique line items) — fixes user-vs-model count confusion B. Add/remove/add_plan return cart state (total, items, units) after every mutation — eliminates verify-cart round-trips C. Store mismatch detection: products table tracks store_id, search warns when cached SKUs are from a different store D. search_batch tool: search up to 15 products in one call instead of N sequential search calls E. Price sanity checking: flags implausible unit prices (e.g. $0.18/lb chicken) with PRICE_DATA_SUSPECT warning F. Remove returns failure reason: not_in_cart (with cart_skus for context), api_error, or cart_fetch_failed — model stops retrying blind G. cart_diff tool: compare expected SKUs against actual cart, showing missing items, extra items, and quantity mismatches H. MCP workflow instructions updated: always check favorites first, use search_batch for multi-item searches, verify cart state from mutation responses, handle store_warning and price_suspect flags I. Blacklist integration: search results flag products matching blacklist notes or avoid_brands from memory 30 new tests covering all features. All 121 non-async tests pass. (38 pre-existing async test failures due to missing pytest-asyncio in this environment are unchanged.) https://claude.ai/code/session_01XuoAmJMDKPhHc7zViFVLQw
- Fix inverted blacklist word matching (note keywords checked against product name, not the other way around) - Add store_id tracking in search_batch (pass to sync_products_from_search) - Fix rate limiting to use 200ms/500ms-per-10 pattern per CLAUDE.md - Add schema migration for store_id column on existing DBs via _migrate() - Add early return for empty expected_skus in cart_diff - Reduce handle_remove from 3 get_cart calls to 2 (skip pre-check; diagnose after remove_from_cart fails; snapshot after success) - Update remove tests to reflect new single-get_cart call pattern https://claude.ai/code/session_01XuoAmJMDKPhHc7zViFVLQw
…hnzfitch/raley-bot into merge-pr7 # Conflicts: # raley_assistant/mcp_server.py
There was a problem hiding this comment.
Pull request overview
This PR merges feature work from PR #7 into main, adding batch search and cart verification tooling, enhancing cart mutation responses with post-action cart state, and extending local DB caching to track the fulfillment store for mismatch detection and price sanity warnings.
Changes:
- Added
search_batchandcart_diffMCP tools plus handler registration, along with blacklist + price sanity warnings insearch. - Enhanced cart/mutation handlers to return
total_unitsand post-mutation cart snapshots, and added structured remove failure reasons. - Added
store_idtracking to the SQLite cache (schema + migration) and introduced store-mismatch detection.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_new_features.py |
Adds test coverage for new cart/search/store-mismatch/blacklist features. |
tests/conftest.py |
Adds test-time mocking for optional mcp dependency imports. |
raley_assistant/reasoning.py |
Introduces check_price_sanity() for implausible price detection. |
raley_assistant/mcp_server.py |
Adds new tools/handlers, cart snapshotting, and search warnings (store mismatch / blacklist / price sanity). |
raley_assistant/db.py |
Adds store_id column + migration and store mismatch detection helper. |
raley_assistant/api.py |
Adds get_store_id() to read current store/fulfillment identifier from session. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+6
to
+12
| # Mock the mcp package if not installed (network may be unavailable) | ||
| if "mcp" not in sys.modules: | ||
| sys.modules["mcp"] = MagicMock() | ||
| sys.modules["mcp.server"] = MagicMock() | ||
| sys.modules["mcp.server.models"] = MagicMock() | ||
| sys.modules["mcp.server.stdio"] = MagicMock() | ||
| sys.modules["mcp.types"] = MagicMock() |
Comment on lines
+648
to
+651
| cart = get_cart(client) | ||
| if not cart: | ||
| return {"cart_total": "$0.00", "cart_items": 0, "cart_units": 0} | ||
| items = cart.get("lineItems", []) |
Comment on lines
+1506
to
+1509
| async def handle_search_batch(args: dict) -> str: | ||
| """Search multiple products at once, return best match per query.""" | ||
| import time | ||
|
|
Comment on lines
+1599
to
+1602
| # Rate limiting between searches: 200ms normally, 500ms every 10 (per CLAUDE.md) | ||
| if i < len(queries) - 1: | ||
| time.sleep(0.5 if (i + 1) % 10 == 0 else 0.2) | ||
|
|
Comment on lines
+1629
to
+1632
| if ":" in part: | ||
| pieces = part.split(":") | ||
| expected[pieces[0].strip()] = int(pieces[1].strip()) if len(pieces) > 1 else 1 | ||
| else: |
Comment on lines
809
to
811
| shown_items = items[:limit] | ||
| response: dict[str, Any] = {"items": shown_items, "count": len(shown_items), "total": f"${total:.2f}"} | ||
| response: dict[str, Any] = {"items": shown_items, "count": len(shown_items), "total_units": total_units, "total": f"${total:.2f}"} | ||
| if full_cart.get("fulfillment_store"): |
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
Conflict Resolution
Test plan
🤖 Generated with Claude Code