Skip to content

Merge PR #7: cart improvements, search_batch, cart_diff, price sanity checks#13

Merged
johnzfitch merged 3 commits into
mainfrom
merge-pr7
Jun 15, 2026
Merged

Merge PR #7: cart improvements, search_batch, cart_diff, price sanity checks#13
johnzfitch merged 3 commits into
mainfrom
merge-pr7

Conversation

@johnzfitch

Copy link
Copy Markdown
Owner

Summary

Conflict Resolution

  • Tool table: Merged both tool sets (store + search_batch/cart_diff)
  • Instructions: Combined cart verification, store/location, and failure handling sections
  • Imports: Added all needed functions (get_store, get_address_book, set_shipping_address, get_store_id)
  • Tool definitions: All three new tools present (store, search_batch, cart_diff)
  • Cart handler: Merged fulfillment context with total_units tracking
  • Handler dispatch: All handlers registered

Test plan

  • All 231 tests pass
  • No conflict markers remaining
  • All handler functions exist and are registered

🤖 Generated with Claude Code

claude and others added 3 commits March 9, 2026 06:34
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
Copilot AI review requested due to automatic review settings June 15, 2026 02:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_batch and cart_diff MCP tools plus handler registration, along with blacklist + price sanity warnings in search.
  • Enhanced cart/mutation handlers to return total_units and post-mutation cart snapshots, and added structured remove failure reasons.
  • Added store_id tracking 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 thread tests/conftest.py
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"):
@johnzfitch
johnzfitch merged commit 9788dd7 into main Jun 15, 2026
1 check passed
@johnzfitch
johnzfitch deleted the merge-pr7 branch June 15, 2026 17:07
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.

3 participants