Skip to content

Gateway admin endpoints /search/optimize and /search/rebuild aren't fenced during staged rebuilds #165

Open

Description

@ViperJuice

Found in independent review of #162, which keeps reads serving from the published generation during a staged rebuild (#145).

Problem

The HTTP gateway's admin endpoints /search/optimize and /search/rebuild (mcp_server/gateway.py, around 2815 and 2875 on the #162 branch) write derived FTS data straight into the published index. They have never been gated on readiness. If a staged rebuild is in progress, the staged generation has already copied the active database, so whatever these endpoints write is superseded at publish, and they still report success.

These are secondary admin operations on derived data, so this doesn't block #162.

Suggested fix

Either refuse with rebuild_in_progress while a live rebuild owner exists, using the same RepoResolver.accepts_writes(ctx) and write-time generation check that #162 adds for summary writes, or run the maintenance inside the staged build instead of against the published DB. Add a test where the endpoint is called during a rebuild and nothing is written to the old generation.

Activity

  1. ViperJuice commented on Nov 23, 2026

    @ViperJuice
    CollaboratorAuthor

    Source review of bcc0f60 found two independent hazards. Both HTTP maintenance routes use the startup-global search backends and store. Resolving a registry entry for preflight can therefore select a different database from the one the route mutates. Even with the correct database, a staged rebuild can snapshot after preflight and before the maintenance commit.

    Resolve the registered target using the existing search selector. Acquire the checkout writer fence before cold store or backend initialization, which can issue DDL. Under the lock, validate the captured generation and file binding and hold it through the final commit. Keep cache effects scoped to that store. Preserve legacy single-store behavior and semantic-only remediation. Registered fuzzy maintenance must use the selected generation's indexed content.

    Regression coverage should use two registered stores plus a distinct global store, and exercise both orderings with a barrier: publication wins before maintenance admission, and maintenance holds the lock through commit. Include same-commit rebuilds, contention and same-path file replacement. This is a proposed fix based on source inspection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions