feat(sofiia-console): harden cursor pagination with tie-breaker

Version cursor payloads and keep backward compatibility while adding dedicated tie-breaker regression coverage for equal timestamps to prevent pagination duplicates and gaps.

Made-with: Cursor
This commit is contained in:
Apple
2026-03-02 08:12:19 -08:00
parent 0c626943d6
commit e504df7dfa
2 changed files with 109 additions and 2 deletions

View File

@@ -3078,7 +3078,8 @@ def _clean_chat_reply(text: str) -> str:
def _cursor_encode(payload: Dict[str, Any]) -> str:
raw = json.dumps(payload, separators=(",", ":"), ensure_ascii=True).encode("utf-8")
wrapped = {"v": 1, **payload}
raw = json.dumps(wrapped, separators=(",", ":"), ensure_ascii=True).encode("utf-8")
return base64.urlsafe_b64encode(raw).decode("ascii")
@@ -3088,7 +3089,17 @@ def _cursor_decode(cursor: Optional[str]) -> Dict[str, Any]:
try:
decoded = base64.urlsafe_b64decode(cursor.encode("ascii")).decode("utf-8")
data = json.loads(decoded)
return data if isinstance(data, dict) else {}
if not isinstance(data, dict):
return {}
# Backward compatibility: accept old cursors without "v".
if "v" not in data:
return data
# Current cursor format version.
if int(data.get("v") or 0) == 1:
out = dict(data)
out.pop("v", None)
return out
return {}
except Exception:
return {}