Skip to content

Add incremental branch indexing for fast-moving branches - #1

Closed
simianhacker wants to merge 2 commits into
mainfrom
incremental-branch-indexing
Closed

Add incremental branch indexing for fast-moving branches#1
simianhacker wants to merge 2 commits into
mainfrom
incremental-branch-indexing

Conversation

@simianhacker

Copy link
Copy Markdown
Owner

What

Adds an opt-in update: incremental mode for branch selectors. Instead of writing a
full commit-addressed snapshot on every branch move, an incremental branch keeps one
mutable, ref-addressed view in new sourcerer-v2-* indices and re-indexes only the files
changed since the last run (typically 10–20), which keeps refresh cost proportional to the
diff rather than the whole repo. The default snapshot path and all existing sourcerer-v1-*
behavior are unchanged.

How to Verify

Against an Elasticsearch/ES|QL cluster that supports index.mode: lookup and LOOKUP JOIN
(9.x):

  1. uv run pytest tests/ — 327 tests pass (uv build also exits 0).
  2. sourcerer setup — loads the v1+v2 templates and creates the v2 refs lookup index plus
    the schema-anchor indices.
  3. Index a branch incrementally with a config containing:
    - org: <org>
      repo: <repo>
      refs:
      - type: branch
        match: main
        update: incremental
    sourcerer index --config repos.yml. Confirm sourcerer-v2-refs has exactly one doc for
    the branch with status: ready, update_mode: incremental, and the completed commit.
  4. Push a commit changing a few files (add/modify/delete/rename), re-run the index. Confirm
    only the changed paths were processed, deleted/rename-source paths leave no docs, and an
    unchanged file's _seq_no is unchanged.
  5. Query via the tools: sourcerer.refs.list shows the incremental ref; pass its exact
    git_ref_key to sourcerer.code.grep / sourcerer.files.cat and confirm rows carry the
    completed commit (attached by the LOOKUP JOIN).

An end-to-end run of steps 2–5 was executed against a live ES 9.5 cluster and passed,
including the mid-first-index visibility case in sourcerer.refs.list.

Breaking Changes

None for existing configs (omitting update keeps the v1 snapshot behavior). Operational
note: the content and refs tools now query both schemas and LOOKUP JOIN sourcerer-v2-refs,
so re-run sourcerer setup after upgrading before relying on the tools — a single setup
creates the required indices before it (re)deploys the Agent Builder tools.

Introduce an isolated `update: incremental` mode for branch selectors that
maintains a single mutable, ref-addressed view of a moving branch in new
`sourcerer-v2-*` indices, re-indexing only the files changed since the last
run instead of re-snapshotting the whole repository on every move. The default
`snapshot` path and all existing `sourcerer-v1-*` behavior are unchanged.

- config: `Selector.update_mode` (`snapshot` default / `incremental`); rejects
  incremental on non-branch selectors and with `since`/`retain`; selection
  raises on a branch selected in both modes and dedupes same-mode overlap.
- indices/templates: `sourcerer-v2-files`, `sourcerer-v2-lines`, and a
  `index.mode: lookup` single-shard `sourcerer-v2-refs`; case-sensitive
  (no-normalizer) `git.ref_key`/`ref`/`org`/`repo` fields.
- documents: ref-addressed v2 file/line builders (no commit in the id) and a
  targeted `index_paths_v2` ingest that indexes a supplied path iterable.
- git: pure NUL-safe `plan_changes` diff planner (add/modify/delete/type-change/
  copy/rename) with an explicit `base_missing` fallback.
- markers: one mutable v2 refs doc per branch with indexing/ready/failure
  writes that only advance the completed commit after success; synchronous,
  ref-scoped `delete_by_query` helpers (`wait_for_completion`, `conflicts=proceed`).
- orchestration: incremental branch units bypass the v1 skip/retention path;
  initial/no-op/targeted-update/retry/missing-base-rebuild flows with failure
  isolation per unit.
- agent builder: `refs.list` returns both schemas with `update_mode`; content
  tools take an exact `git_ref_key` and use mutually-exclusive snapshot/ref-key
  scoping plus a `LOOKUP JOIN sourcerer-v2-refs` to attach the completed commit
  for citations; ref-resolution/citations skills document the flow.
- setup: creates the v2 refs lookup index and empty schema-anchor indices so
  the dual-schema ES|QL resolves `git.commit`/`git.ref_key` on any cluster.
- docs: README, AGENTS.md, repos.example.yml cover config, the mixed-revision
  consistency window, the v1/v2 boundary, and a local evaluation procedure.
- refs.list: tolerate null git.commit so an incremental branch mid- (or failed)
  first index is still listed (was silently filtered by null LIKE "*"); + test.
- AGENTS.md: document that setup must be re-run after upgrade before the tools
  work (setup creates the v2 lookup + schema-anchor indices before deploying the
  Agent Builder tools, so a single setup keeps the ordering correct).
@simianhacker

Copy link
Copy Markdown
Owner Author

Superseded by elastic#1 (filed against upstream).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant