Repository navigation
fix(memories): sanitize internal exception detail in batch-delete 413 response - #19520
Conversation
The canonical batch mutation limit error surfaced raw str(exc) as the 413 detail, the only non-static HTTPException detail left in memory_service.py. The internal reason (memory id + data-layer transaction limits) is now logged server-side through utils.log_sanitizer.sanitize with exc_info, and the client keeps the released 413 status with a static message.
|
Thank you for this clean, well-scoped fix — verified against the bounty description (#19519, still open) and the current head.
I also checked for consumers of the previous dynamic wording and found none — the status code is unchanged and the router contract tests pass the service error through generically, so this is contract-safe. Backend checks are green at this head. Nice catch on the last raw exception reflection in this path. Leaving the merge sign-off to a maintainer given this touches a user-data API error surface. Feedback generated by AI on behalf of the maintainers. Conclusions verified against the diff and CI logs at head a6ed92b. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
fix(backend): sanitizes leaked internal exception detail in batch-delete 413 response; scoped diff, regression test added, no already-fixed conflict.
|
Hi |
What changed and why
MemoryService.delete_batch(backingDELETE /v3/memories/batch) mapped an over-limit canonical batch toHTTPException(413, detail=str(exc))— the only raw exception reflection left among the file's ~120HTTPExceptionraises. The data layer's internal reason (internal memory id + Firestore transaction-limit wording) was returned verbatim to the API client.The mapping now logs the reason server-side through
utils.log_sanitizer.sanitizewithexc_info=True, and answers with a static detail (Memory batch exceeds the supported size limit) while preserving the released 413 status. The internal exception remains chained (from exc).Bounty proposal: #19519
Product invariants affected
How it was verified
python -m pytest tests/unit/test_universal_memory_service.py -q-> 107 passed (includes the new regression test)python -m pytest tests/unit/test_memories_batch_delete.py -q-> 11 passed (router contract: 402/404/413 mapping, rate limit, and route order preserved)python -m pytest tests/unit/test_atomicity_lifecycle_regressions.py -q-> 22 passedblack --line-length 120 --skip-string-normalization --check <files>-> unchangedTests
New regression test
test_delete_batch_limit_error_sanitizes_detail_and_preserves_413intests/unit/test_universal_memory_service.py: drives the real service path with an injectedCanonicalBatchMutationLimitErrorthat carries an internal memory id and Firestore wording; asserts status 413, the exact static detail, no internal markers in the response, a masked log line, and the chained cause.Failure class (fixes)
Failure-Class: none
Line-Count-Exception: backend/utils/memory/memory_service.py | 4334 -> 4342 | Sanitize the batch-delete 413 detail: static client message, sanitized server-side log with exc_info, and chained cause; +8 lines, no restructuring.