Repository navigation
fix(search): raise Meilisearch task-wait timeout from 5m to 2h - #347
Conversation
📝 WalkthroughWalkthroughThe default Meilisearch task wait timeout constant was changed from 5 minutes to 2 hours, altering the maximum polling duration applied when no explicit context deadline is set for task completion checks. ChangesTask Wait Timeout Update
Estimated code review effort: 1 (Trivial) | ~2 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing — opened without an explicit go-ahead. The branch remains at RXWatcher:fix/meilisearch-index-cleanup if this is wanted later. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56468934da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } `json:"results"` | ||
| Total int `json:"total"` | ||
| } | ||
| endpoint := fmt.Sprintf("/indexes?limit=200&offset=%d", offset) |
There was a problem hiding this comment.
Build the list-index URL with a real query string
When superseded-index cleanup runs, this endpoint is passed to c.do, which assigns it to URL.Path via path.Join; the ?limit=... portion is therefore encoded into the path (/indexes%3Flimit=...) instead of becoming RawQuery. In any rebuild that reaches cleanup, the Meilisearch list call will hit the wrong route/no query, log a failure, and leave all old rebuild indexes behind, defeating the storage cleanup this change adds.
Useful? React with 👍 / 👎.
| // copies behind. Cleanup runs on a detached context because the usual | ||
| // failure cause is the run context dying. | ||
| swapped := false | ||
| defer func() { |
There was a problem hiding this comment.
Register abandoned-index cleanup before waiting for creation
The cleanup defer is installed only after WaitTask for the create-index task returns. If the rebuild context is canceled or times out after CreateIndex successfully enqueues the task but before the wait completes, Rebuild returns before this defer exists, while Meilisearch can still finish creating <base>_rebuild_*; that leaves exactly the abandoned index this cleanup is meant to remove. Move the defer registration immediately after a successful CreateIndex call, or explicitly delete on create-task wait failure.
Useful? React with 👍 / 👎.
|
Pushed fixes for both findings: |
- do() now splits an optional query string off the endpoint before path.Join, which would otherwise percent-encode "?" into the path — ListIndexUIDs' pagination query was routed nowhere, so the superseded- index sweep silently swept nothing. - Register the abandoned-index cleanup defer before waiting on the create task, not after: the run context can die during that wait while Meilisearch still finishes creating the index. The delete task queues behind the create task, so it removes the index either way. Co-Authored-By: Claude Fable 5 <[email protected]>
Semantic (vector-embedded) index batches can take Meilisearch many minutes on modest hardware, and Meilisearch auto-batches consecutive queued document tasks — with rebuild_task_queue_depth tasks in flight the oldest task's completion covers the whole fused unit. WaitTask's 5-minute default deadline killed four prod rebuilds mid-batch (2026-06-29 x2, 2026-07-08 x2) with "context deadline exceeded", each time leaving incremental sync blocked on a stale schema version and an unbounded event backlog (1.6M+ events). The wait still exits immediately when the task reaches a terminal state (succeeded/failed/canceled); the deadline only bounds tasks genuinely still processing, where giving up guarantees rebuild failure and gains nothing. Co-Authored-By: Claude Fable 5 <[email protected]>
07f2664 to
4eb7add
Compare
58d88e5 to
4eb7add
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/catalog/search_meilisearch_client.go (1)
304-325: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueConsider backoff for long-running task polls.
With the 2-hour timeout and a 1-second polling interval, a single long-running task could generate up to ~7,200 HTTP GET requests. This isn't a correctness issue — Meilisearch handles the load fine — but an exponential or stepped backoff (e.g., start at 1s, cap at 30–60s) would reduce unnecessary polling traffic during extended processing without sacrificing responsiveness for quick tasks.
This can be deferred since the current change is a targeted, prod-validated hotfix.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/catalog/search_meilisearch_client.go` around lines 304 - 325, The polling loop in the Meilisearch task waiter currently uses a fixed 1-second ticker, which can create excessive GET traffic for long-running tasks. If you decide to address it in the polling path around c.do and the meilisearchTask status loop, replace the constant interval with an exponential or stepped backoff that starts near 1s and increases up to a capped maximum while preserving quick checks for fast-completing tasks. Keep the existing success/failure handling intact and continue honoring ctx cancellation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/catalog/search_meilisearch_client.go`:
- Around line 304-325: The polling loop in the Meilisearch task waiter currently
uses a fixed 1-second ticker, which can create excessive GET traffic for
long-running tasks. If you decide to address it in the polling path around c.do
and the meilisearchTask status loop, replace the constant interval with an
exponential or stepped backoff that starts near 1s and increases up to a capped
maximum while preserving quick checks for fast-completing tasks. Keep the
existing success/failure handling intact and continue honoring ctx cancellation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9843db84-c62f-473e-9e69-b74013b619e4
📒 Files selected for processing (1)
internal/catalog/search_meilisearch_client.go
Semantic (vector-embedded) index batches can take Meilisearch many minutes on modest hardware, and Meilisearch auto-batches consecutive queued document tasks — with rebuild_task_queue_depth tasks in flight the oldest task's completion covers the whole fused unit. WaitTask's 5-minute default deadline killed four prod rebuilds mid-batch (2026-06-29 x2, 2026-07-08 x2) with "context deadline exceeded", each time leaving incremental sync blocked on a stale schema version and an unbounded event backlog (1.6M+ events). The wait still exits immediately when the task reaches a terminal state (succeeded/failed/canceled); the deadline only bounds tasks genuinely still processing, where giving up guarantees rebuild failure and gains nothing. Co-authored-by: rxwatcher <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Problem
WaitTask's hard-coded 5-minute deadline killed four prod catalog rebuilds mid-batch ("context deadline exceeded"): twice on 2026-06-29 and twice on 2026-07-08 — the latter even after shrinkingrebuild_batch_sizeto 1000 on an 8-core Meilisearch. Each death leaves incremental sync gated on a stale schema version while the event outbox grows unboundedly (1.6M+ rows on prod): search silently frozen.Batch size can't fully mitigate because Meilisearch auto-batches consecutive queued document tasks — with
rebuild_task_queue_depthtasks in flight, the oldest task only completes when the whole fused unit does, which exceeds 5 minutes in vector-heavy stretches of the catalog.Change
Raise
defaultMeilisearchTaskWaitTimeoutto 2 hours, with the incident history documented on the constant. Terminal task states (succeeded/failed/canceled) still end the wait immediately — the deadline only bounds a task genuinely still processing, where giving up guarantees rebuild failure and gains nothing.Validation
Running on prod (2026-07-08) via a hotfix image; the rebuild that failed four times is running with 2h headroom.
go build/go vet/go test ./internal/catalog/pass. Rebased onto current main (the index-cleanup work this PR briefly carried was dropped as redundant with #291).Companion PR from the same incident: #340 (smart collection cap removal).
AI-use disclosure
Implemented with Claude Code (Claude Fable 5); prod-validated.
🤖 Generated with Claude Code
Summary by CodeRabbit