Skip to content

fix(search): raise Meilisearch task-wait timeout from 5m to 2h - #347

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
RXWatcher:fix/meilisearch-index-cleanup
Jul 9, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
RXWatcher:fix/meilisearch-index-cleanup

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

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 shrinking rebuild_batch_size to 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_depth tasks 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 defaultMeilisearchTaskWaitTimeout to 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

  • Bug Fixes
    • Increased the maximum wait time for search indexing tasks, reducing the chance of timeouts when processing longer-running updates.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Task Wait Timeout Update

Layer / File(s) Summary
Default timeout constant update
internal/catalog/search_meilisearch_client.go
defaultMeilisearchTaskWaitTimeout increased from 5 minutes to 2 hours.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested labels: v1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: extending the Meilisearch task-wait timeout.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RXWatcher

Copy link
Copy Markdown
Contributor Author

Closing — opened without an explicit go-ahead. The branch remains at RXWatcher:fix/meilisearch-index-cleanup if this is wanted later.

@RXWatcher RXWatcher closed this Jul 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread internal/catalog/search_indexer.go Outdated
// copies behind. Cleanup runs on a detached context because the usual
// failure cause is the run context dying.
swapped := false
defer func() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 8, 2026
@RXWatcher RXWatcher reopened this Jul 8, 2026
@RXWatcher RXWatcher changed the title fix(search): delete superseded and abandoned Meilisearch rebuild indexes fix(search): Meilisearch rebuild robustness — index cleanup + task-wait timeout Jul 8, 2026
@RXWatcher

Copy link
Copy Markdown
Contributor Author

Pushed fixes for both findings: do() now splits the query string off the endpoint before path.Join (the pagination query was indeed being percent-encoded into the path), and the abandoned-index cleanup defer registers before the create-task wait, with the delete task queuing behind the create task so the index is removed even when the context dies mid-creation.

RXWatcher added a commit to RXWatcher/silo-server that referenced this pull request Jul 8, 2026
- 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]>
@RXWatcher
RXWatcher force-pushed the fix/meilisearch-index-cleanup branch from 07f2664 to 4eb7add Compare July 8, 2026 19:05
@RXWatcher RXWatcher changed the title fix(search): Meilisearch rebuild robustness — index cleanup + task-wait timeout fix(search): raise Meilisearch task-wait timeout from 5m to 2h Jul 8, 2026
@RXWatcher RXWatcher changed the title fix(search): raise Meilisearch task-wait timeout from 5m to 2h fix(search): 2h Meilisearch task-wait timeout + uncapped smart collections Jul 8, 2026
@RXWatcher
RXWatcher force-pushed the fix/meilisearch-index-cleanup branch from 58d88e5 to 4eb7add Compare July 8, 2026 20:00
@RXWatcher RXWatcher changed the title fix(search): 2h Meilisearch task-wait timeout + uncapped smart collections fix(search): raise Meilisearch task-wait timeout from 5m to 2h Jul 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/catalog/search_meilisearch_client.go (1)

304-325: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab55cb and 4eb7add.

📒 Files selected for processing (1)
  • internal/catalog/search_meilisearch_client.go

@Quick104
Quick104 merged commit 581f39b into Silo-Server:main Jul 9, 2026
2 checks passed
Quick104 pushed a commit that referenced this pull request Jul 10, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants