Repository navigation
Fix supermarket basket orphan rows and add remove_basket_item - #459
Merged
Merged
Conversation
Order.Sync puts the wanted quantity in changes.remove, but CartItems.apply_changes sent quantity 0 for every removal, so shrinking a row deleted it instead of reducing it. A decrease from 3 to 1 now leaves 1 in the basket. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
edit_ingredient only changed the database, so Order.Sync kept treating the old product as an external basket row and it stayed forever with no ingredient linked. Order.remap_basket_product now swaps the row while the ingredient is on the current order, keeps the wanted quantity, and writes nothing while the order is placed or the ingredient is not on the list. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Rows with ingredient: null had no MCP cleanup path: the agent could not touch them and the user deleted them by hand. The new tool removes one by supermarket product id, refuses rows an ingredient claims, missing products, non-ah modes and the placed-order freeze, and reports what it removed. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
start_shopping moved the plan rows and snapshotted the basket, but the plan's products stayed behind. The next sync saw them as external rows and kept them, so leftovers from the closed order lingered in the new one. Closing now removes exactly the products the plan wanted, after substitution, intersected with what is in the basket. Rows Picape does not own, like products added in the supermarket's own app, stay. Frozen while the paid order is still being processed. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
mark_recipe_as_cooked inserted a PlannedRecipe row for a recipe that was never planned, which made it look planned and reported is_cooked: false anyway because cooked is not a cast field. It now updates an existing row only and reports :not_on_order. archive_placed_order wrote the PlacedOrder marker before fetching the cart. A flaky fetch raised after the marker committed, so every retry skipped the archive and the plan stayed on the open order. The fetch now runs first and falls back to an empty snapshot like the other supermarket reads. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
remap_basket_product read the wanted quantity from cart/1, which is keyed per ingredient and ignores substitution. The wanted set sync actually pushes is substitute/2 of the merged plan quantities, so a remap onto an unavailable product could add a row sync never wanted. Both remap and the order-close cleanup now share wanted_basket_quantities/2. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
UpdateMyListBasket can answer SUCCESS while a row survives, for example a row in externalItems that the fake keeps untouched. After each removal or swap, invalidate the cart cache, read it back and check the product is gone, or that the swapped product shows the expected quantity. remove_basket_item now returns an error naming the section when the supermarket keeps the row, and publishes the order change on success like start_shopping does. The swap and the close-order cleanup run inside larger operations, so they log a warning instead. Also refresh the cart before remove_basket_item reads it, and cover the tool's picnic mode, string and missing product id, and the surviving externalItems row with tests.
The close-order cleanup only removed products the plan wanted at a positive quantity, so a row the plan wanted gone stayed in the basket, and a product pushed before it became unavailable with a replacement was never considered either. wanted_basket_quantities now returns the wanted set both before and after substitution, and shopped_product_ids unions both key sets without the positive-quantity filter, matching sync semantics: a wanted zero means sync removes the row, and either side of a substitution may be the row that sits in the basket. Anything else may be the user's own addition in the supermarket's app and stays.
remap_basket_product required the old product to sit in the basket before it pushed the new one. When the old row was already absent, for example after a failed push, the swap was skipped and the new product never reached the basket: edit_ingredient reported ordered_quantity 0 and the ingredient vanished from the shopping list. The swap now reads the substituted wanted quantity and pushes the new product unconditionally; removing an absent old row is a no-op. It also invalidates the cart cache before reading, like the other basket writes, and the doc says the row lands at the plan's wanted quantity, not the old row's quantity.
The archive comment claimed the cart fetch runs before the marker, but what makes a flaky read safe is that ordered_supermarket_items rescues it to an empty snapshot like the other supermarket reads. The README said the remapped row keeps its quantity; it actually lands at the plan's wanted quantity.
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
edit_ingredientremaps now move the basket row: the old supermarketproduct leaves the basket and the new one gets the wanted quantity, with
the same placed-order freeze as every other basket write.
remove_basket_itemdeletes a basket row that no ingredientis linked to (
ingredient: nullinget_shopping_list), by supermarketproduct id. It refuses linked rows (points to
set_ingredient_quantity),missing products, non-ah modes and the placed-order freeze.
start_shoppingnow removes the closed plan's own products from thebasket so the next order does not inherit them. Rows Picape does not own,
like products added in the supermarket's own app, stay.
CartItems.apply_changessends the target quantity for reductions insteadof always 0, so shrinking a row no longer deletes it.
archive_placed_orderfetches the cart before writing thePlacedOrdermarker, so a flaky fetch no longer skips the archive on every retry.
mark_recipe_as_cookedupdates an existing plan row only; it no longerinserts phantom
order_planned_reciperows for unplanned recipes.Test plan
mix check— format, credo, compile, 206 tests, sobelow all passorphan removal (5 cases), order-close cleanup preserving external
rows, quantity reduction, flaky archive fetch, cooked marking
Reported by the grocery agent on 9 Nov 2026 (orphan rows after remaps, leftovers after closing an order). Written with Devin SWE-2 Flash High; adversarial review by SWE-2 High follows. Not for merge until reviewed.