Repository navigation
fix(memorize): bound the bodies failed async batches keep - #607
Conversation
gloryfromca
left a comment
There was a problem hiding this comment.
Blocking: enforce the failed-body budget while a drain remains busy.
I reviewed the repository guidance (CLAUDE.md and the applicable .claude/rules), the requested origin/main...HEAD diff, the live PR base and actual one-commit delta, surrounding queue callers/ports/adapters, relevant history, backward compatibility of the new setting, docs, test changes, and architecture constraints. The local origin/main ref is stale; GitHub reports the PR base as the immediate parent c2c8d6f, so the substantive review used that one-commit delta.
All lint-equivalent checks passed: Ruff, formatting, import-layer contracts, asset/size/name/contributor-doc checks, datetime and singleton checks, and OpenAPI drift. The 51 directly relevant repository/queue tests passed. The full unit run reported 4,099 passed, 4 skipped, and 10 failures because the environment lacked the declared NLTK datasets; attempting the repository's downloader command produced invalid downloaded archives, and rerunning that tokenizer module still gave 10 environment-related failures. No tests were weakened or skipped to obtain a green result.
One blocking correctness issue is inline.
13d6eb8 to
883efd0
Compare
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
Reviewed the refreshed origin/main...HEAD change, the delta from the previously reviewed revision, the queue scheduling callers and history, configuration/docs compatibility, test strength, and the repository's architecture and coding rules. The in-drain deadline check fixes the reported starvation path without changing the storage contract, and the continuously replenished failure test covers that path. The later b4f3e703 commit changes only the purge state-machine model so a simulated dead process cannot deliver before restart; it does not weaken the queue-budget coverage or alter production code.
Verification: 56 focused queue/repository/stateful tests passed; all lint-equivalent gates passed (Ruff, formatting, import contracts, repository policy checks, datetime/singleton checks, and OpenAPI drift). On live head b4f3e703, all 5 purge interleaving tests passed with 2 aiosqlite resource warnings, and the changed test file passed Ruff and format checks. The prior blocker was verified fixed, replied to, and its thread resolved.
b4f3e70 to
b707f50
Compare
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
This head is a rebase of the already-reviewed three commits. I checked the refreshed origin/main...HEAD diff, commit history, relevant queue callers, compatibility/config/docs, test strength, and the repository architecture/rules. The queue implementation and focused queue tests have the same Git blob IDs as the previously clean revision, and the crash-model test commit has the same stable patch ID; the prior fix and resolved finding are unchanged.
Verification on the rebased tree: 56 focused queue/repository/stateful tests passed, and all 5 purge interleaving tests passed. The integration run emitted 12 aiosqlite connection ResourceWarnings but no test failures. No tests were weakened in this rebase.
b707f50 to
a170d20
Compare
|
Stacked on #618: both edit the CHANGELOG [Unreleased] section, |
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
Reviewed origin/fix/refuse-cross-site-requests...HEAD, the rebase/stack delta, queue callers and history, compatibility of the overlapping settings/default/docs changes, test strength, and the repository architecture/rules. The queue implementation and focused tests are unchanged from the previously clean revision; the first and third commits are stable-patch identical, and the middle commit differs only in stack-context text around the same reviewed fix. The resolved finding remains fixed.
Verification on the stacked tree: 56 queue/repository/stateful tests passed, all 23 cross-site middleware tests passed, and Ruff passed over the overlapping config, queue, and middleware areas. No tests were weakened.
A failed memorize_inbox row kept its request body for the whole retention window with no cap, so an outage that failed every async batch held every body accepted during it on disk (up to 4 MiB each). The queue sweep now empties the bodies of failed rows past the newest max_failed_payload_bytes (default 64 MiB); the row, its status and last_error stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sweep (retention purge, failed-body trim) ran only before a drain, and a drain returns only once nothing is queued or in flight. Under an outage with steady traffic every failed row is replaced before the drain empties, so failed bodies grew past max_failed_payload_bytes. The drain now sweeps before each claim once scan_interval_seconds has passed since the last sweep; the loop no longer sweeps on every wake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claim_and_crash left a row processing as if the process had died in it, then let the same process keep draining. drain_once now runs the queue sweep itself, which fails processing rows this scheduler is not running, so the row was failed instead of replayed. Production never drains in that state: start() requeues processing rows before the first drain, and the loop already swept before every drain. The rule now marks the crash like crash_mid_event does, and deliver_one waits for the restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a170d20 to
3c0b5b7
Compare
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
Reviewed 3c0b5b7be6c6 after the rebase onto current main. Comparing the complete three-commit patch with the previously reviewed stack found only base-context and line-number changes; the failed-body budget fix and its busy-drain regression coverage are substantively unchanged. The new base's purge timing change does not conflict with this patch.
Covered the repository rules, current diff, affected queue/persistence callers, commit history and rebase equivalence, configuration compatibility, architecture boundaries, and whether tests were weakened. Verification: 56 focused queue/repository tests passed, 28 purge-runner tests passed, 5 purge interleaving tests passed (with 5 existing non-failing aiosqlite ResourceWarnings), focused Ruff passed, and git diff --check passed.
Summary
A
failedasync memorize row kept its request body for the full seven-day retention with no cap (documented indocs/api.mdas a known gap). An outage that fails every async batch therefore kept every body accepted during it on disk, up to 4 MiB each, with no bound other than how many requests arrived.The queue's existing sweep (every
scan_interval_seconds) now empties the bodies of failed rows past the newestmemorize.async_queue.max_failed_payload_bytes(default 64 MiB,0keeps none). The row, its status andlast_errorstay, soGET /tasks/{id}still reports the failure; the newest failed bodies remain available for re-sending.MemorizeInboxStore.trim_failed_payloads(max_bytes): oneUPDATE … WHERE id IN (window-sum over failed rows, newest first); sizes are UTF-8 bytes._sweepcalls it afterpurge_expired; like the purge it logs and never raises (memorize_queue_failed_bodies_dropped/memorize_queue_trim_failed).default.toml,docs/configuration.md, the retention paragraph indocs/api.md, andCHANGELOG.md(Unreleased / Fixed).Area
Verification
Checklist
main..envfiles, dependency folders, or generated output.Notes for Reviewers
max_pending_total * max_payload_bytes); this bounds the failed rows' share. SQLite still does not shrinksystem.db; freed pages are reused.By submitting this pull request, I agree that my contribution is licensed under
the Apache License 2.0.
🤖 Generated with Claude Code