From b46819163bada1e7250707e9011d32d9bcbf9540 Mon Sep 17 00:00:00 2001 From: Conan Scott Date: Wed, 1 Jul 2026 18:38:00 +1000 Subject: [PATCH] fix(tokenize): drop Limit=1 in customer resolution scan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DynamoDB's `Limit` caps items scanned *before* the FilterExpression runs, so `scan(FilterExpression=name==X, Limit=1)` returns nothing when the first row scanned isn't the match. Worked with one seeded customer; adding a second (cust-0002) made 王小明 fail to resolve to a customer_id, so the RAG tool returned "token did not resolve" and the agent replied "no customer found". Remove the Limit; the small table is filtered in full. Co-Authored-By: Claude Opus 4.8 --- gateway_api/tokenize/handler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gateway_api/tokenize/handler.py b/gateway_api/tokenize/handler.py index ba277a8..373ff54 100644 --- a/gateway_api/tokenize/handler.py +++ b/gateway_api/tokenize/handler.py @@ -89,14 +89,17 @@ def _analyze(text, language="zh"): def _resolve_customer_id(name): - # Demo-grade name -> customer_id resolution (one seeded customer, so a scan is + # Demo-grade name -> customer_id resolution (small table, so a filtered scan is # fine). Best effort: if it fails we still tokenize, just without a RAG link. + # NOTE: no `Limit` -- in DynamoDB, Limit caps items *scanned* before the filter + # runs, so `Limit=1` returns nothing when the first row scanned isn't the match + # (broke once a 2nd customer existed). A GSI on `name` would be the prod fix. if not CUSTOMERS: return None try: from boto3.dynamodb.conditions import Attr - res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name), Limit=1) + res = CUSTOMERS.scan(FilterExpression=Attr("name").eq(name)) items = res.get("Items", []) return items[0]["customer_id"] if items else None except Exception: